Disable the browser's native spellchecking ability on all form inputs, except for DText inputs. We do this by setting `spellcheck="false"` on the <body> tag, and `spellcheck="true"` on DText <input> tags. This fixes browsers displaying a red wavy underline beneath tags in the tag search box, among other places. We disable spellchecking globally because most form inputs, except for DText inputs, aren't meant for natural English language.
31 lines
1.1 KiB
Ruby
31 lines
1.1 KiB
Ruby
# A custom SimpleForm input for DText fields.
|
|
#
|
|
# Usage:
|
|
#
|
|
# <%= f.input :body, as: :dtext %>
|
|
# <%= f.input :reason, as: :dtext, inline: true %>
|
|
#
|
|
# https://github.com/heartcombo/simple_form/wiki/Custom-inputs-examples
|
|
# https://github.com/heartcombo/simple_form/blob/master/lib/simple_form/inputs/string_input.rb
|
|
# https://github.com/heartcombo/simple_form/blob/master/lib/simple_form/inputs/text_input.rb
|
|
|
|
class DtextInput < SimpleForm::Inputs::Base
|
|
enable :placeholder, :maxlength, :minlength
|
|
|
|
def input(wrapper_options)
|
|
t = template
|
|
merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
|
|
|
|
t.tag.div(class: "dtext-previewable", spellcheck: true) do
|
|
if options[:inline]
|
|
t.concat @builder.text_field(attribute_name, merged_input_options)
|
|
else
|
|
t.concat @builder.text_area(attribute_name, { rows: 20, cols: 30 }.merge(merged_input_options))
|
|
end
|
|
|
|
t.concat t.tag.div(id: "dtext-preview", class: "dtext-preview prose")
|
|
t.concat t.tag.span(t.link_to("Formatting help", t.dtext_help_path, remote: true, method: :get), class: "hint dtext-hint")
|
|
end
|
|
end
|
|
end
|