lib/trix/form.rb in trix-editmode-0.0.1 vs lib/trix/form.rb in trix-editmode-0.0.2

- old
+ new

@@ -6,18 +6,16 @@ class_variable_set('@@id', 0) def trix_editor_tag(name, value = nil, options = {}) options.symbolize_keys! - css_class = Array.wrap(options[:class]).join(' ') - attributes = { class: "formatted_content trix-content #{css_class}".squish } - attributes[:autofocus] = true if options[:autofocus] - attributes[:input] = options[:input] || "trix_input_#{TrixEditorHelper.id += 1}" + css_class = Array.wrap(options.delete(:class)).join(' ') + attributes = { + class: "formatted_content trix-content #{css_class}".squish, + input: "trix_input_#{TrixEditorHelper.id += 1}" + }.merge(options) - valid_html_options = [:placeholder, :spellcheck, :toolbar, :tabindex] - attributes.merge!(options.slice(*valid_html_options)) - editor_tag = content_tag('trix-editor', '', attributes) input_tag = hidden_field_tag(name, value, id: attributes[:input]) input_tag + editor_tag end @@ -34,10 +32,17 @@ 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) + + value = if Rails.gem_version >= Gem::Version.new('5.2.x') + options.delete('value') { value_before_type_cast } + else + value_before_type_cast(object) + end + + trix_editor_tag(options.delete('name'), value, options) end end end module FormHelper