Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support provided value in form helper #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/trix/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def render
options = @options.stringify_keys
add_default_name_and_id(options)
options['input'] ||= dom_id(object, [options['id'], :trix_input].compact.join('_'))
trix_editor_tag(options.delete('name'), value_before_type_cast(object), options)
trix_editor_tag(options.delete('name'), (options['value'] || value_before_type_cast(object)), options)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you extract the value setting to a separate variable?

end
end
end
Expand Down
14 changes: 14 additions & 0 deletions spec/trix_editor_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@
assign(:blog, blog)
expect(helper.trix_editor(:blog, :text)).to include('trix-editor')
end

it 'uses value from object' do
blog = mock_model('Blog', text: 'my_original_value')

assign(:blog, blog)
expect(helper.trix_editor(:blog, :text)).to include('my_original_value')
end

it 'uses a provided value instead of value from object' do
blog = mock_model('Blog', text: 'my_original_value')

assign(:blog, blog)
expect(helper.trix_editor(:blog, :text, value: "my_provided_value")).to include('my_provided_value')
end
end

describe '#trix_editor_tag' do
Expand Down