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

Use either the id from input_html or rails default #58

Open
wants to merge 2 commits 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
3 changes: 2 additions & 1 deletion lib/trix/simple_form/trix_editor_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ module Trix
module SimpleForm
class TrixEditorInput < ::SimpleForm::Inputs::Base
def input(_wrapper_options)
editor_tag = template.content_tag('trix-editor', '', input: input_class, class: 'trix-content')
trix_input = input_html_options[:id] || input_class
editor_tag = template.content_tag('trix-editor', '', input: trix_input, class: 'trix-content')
hidden_field = @builder.hidden_field(attribute_name, input_html_options)

template.content_tag('div', editor_tag + hidden_field, class: 'trix-editor-wrapper')
Expand Down
12 changes: 12 additions & 0 deletions spec/simple_form/simple_form_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,16 @@
it 'outputs HTML containing the trix editor tag with a trix-content class' do
assert_select 'trix-editor.trix-content'
end

context 'changing html_options' do
let(:form) do
simple_form_for(post, url: 'some-url') do |f|
f.input(:body, as: :trix_editor, input_html: { id: 'custom' })
end
end

it 'outputs HTML containing the trix editor pointing to the correct input id' do
assert_select 'trix-editor[input="custom"]'
end
end
end