Class: Brut::FrontEnd::Components::Inputs::TextareaTag
- Inherits:
-
Brut::FrontEnd::Components::Input
- Object
- Phlex::HTML
- Brut::FrontEnd::Component
- Brut::FrontEnd::Components::Input
- Brut::FrontEnd::Components::Inputs::TextareaTag
- Defined in:
- lib/brut/front_end/components/inputs/textarea_tag.rb
Overview
Generates an HTML <textarea>
field based on a form input.
Instance Method Summary collapse
-
#initialize(form:, input_name:, index: nil, **html_attributes) ⇒ TextareaTag
constructor
Creates the appropriate textarea for the given Form and input name.
-
#invalid? ⇒ Boolean
-
#view_template ⇒ Object
Methods inherited from Brut::FrontEnd::Component
#around_template, component_name, #component_name
Methods included from Brut::FrontEnd::Component::Helpers
#entity, #global_component, #inline_svg
Methods included from I18n::ForHTML
Methods included from I18n::BaseMethods
#l, #t, #t_direct, #this_field_value
Methods included from Brut::Framework::Errors
Constructor Details
#initialize(form:, input_name:, index: nil, **html_attributes) ⇒ TextareaTag
Creates the appropriate textarea for the given Form and input name.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/brut/front_end/components/inputs/textarea_tag.rb', line 10 def initialize(form:, input_name:, index: nil, **html_attributes) html_attributes = html_attributes.map { |key,value| [ key.to_sym, value ] }.to_h default_html_attributes = {} index ||= 0 input = form.input(input_name, index:) default_html_attributes[:required] = input.required default_html_attributes[:name] = if input.array? "#{input.name}[]" else input.name end if input.maxlength default_html_attributes[:maxlength] = input.maxlength end if input.minlength default_html_attributes[:minlength] = input.minlength end if !form.new? && !input.valid? default_html_attributes["data-invalid"] = true input.validity_state.each do |constraint,violated| if violated default_html_attributes["data-#{constraint}"] = true end end end @value = input.value @attributes = default_html_attributes.merge(html_attributes) end |
Instance Method Details
#invalid? ⇒ Boolean
41 |
# File 'lib/brut/front_end/components/inputs/textarea_tag.rb', line 41 def invalid? = @attributes["data-invalid"] == true |
#view_template ⇒ Object
43 44 45 46 47 |
# File 'lib/brut/front_end/components/inputs/textarea_tag.rb', line 43 def view_template textarea(**@attributes) { @value } end |