From 520b9ce30e683dd829b8e8ae6b7a9dc2162c0e7e Mon Sep 17 00:00:00 2001 From: Waldyr de Souza Date: Thu, 26 Oct 2017 12:07:54 +0200 Subject: [PATCH 1/2] Add test case to cover manually changes in input id --- spec/simple_form/simple_form_integration_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/simple_form/simple_form_integration_spec.rb b/spec/simple_form/simple_form_integration_spec.rb index 13f0f1b7..0934578b 100644 --- a/spec/simple_form/simple_form_integration_spec.rb +++ b/spec/simple_form/simple_form_integration_spec.rb @@ -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 From e4c3ec28a08ab7360a863626653051ee2ae5c6d9 Mon Sep 17 00:00:00 2001 From: Waldyr de Souza Date: Thu, 26 Oct 2017 12:08:39 +0200 Subject: [PATCH 2/2] Use either the id from input_html or rails default --- lib/trix/simple_form/trix_editor_input.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/trix/simple_form/trix_editor_input.rb b/lib/trix/simple_form/trix_editor_input.rb index 3ad37c5d..c5f337d3 100644 --- a/lib/trix/simple_form/trix_editor_input.rb +++ b/lib/trix/simple_form/trix_editor_input.rb @@ -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')