Class: ShadcnPhlexcomponents::FormInput
- Includes:
- FormHelpers
- Defined in:
- lib/shadcn_phlexcomponents/components/form/form_input.rb
Constant Summary
Constants inherited from Base
Base::SANITIZER_ALLOWED_ATTRIBUTES, Base::SANITIZER_ALLOWED_TAGS, Base::TAILWIND_MERGER
Instance Method Summary collapse
-
#initialize(method = nil, model: false, object_name: nil, type: :text, value: nil, name: nil, id: nil, label: nil, error: nil, hint: nil, **attributes) ⇒ FormInput
constructor
A new instance of FormInput.
- #view_template ⇒ Object
Methods included from FormHelpers
#aria_attributes, #default_checked, #default_error, #default_value, #describedby, #hint, #hint_attributes, #label, #label_and_hint_container_attributes, #label_attributes, #render_error, #render_hint, #render_label
Methods inherited from Base
#before_template, #convert_collection_hash_to_struct, #default_attributes, #find_as_child, #icon, #item_disabled?, #merge_default_attributes, #merged_as_child_attributes, #nokogiri_attributes_to_hash, #overlay, #sanitize_as_child
Constructor Details
#initialize(method = nil, model: false, object_name: nil, type: :text, value: nil, name: nil, id: nil, label: nil, error: nil, hint: nil, **attributes) ⇒ FormInput
Returns a new instance of FormInput.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/shadcn_phlexcomponents/components/form/form_input.rb', line 7 def initialize( method = nil, model: false, object_name: nil, type: :text, value: nil, name: nil, id: nil, label: nil, error: nil, hint: nil, **attributes ) @method = method @model = model @object_name = object_name @type = type.to_sym @value = default_value(value, method) @name = name @id = id @label = label @error = default_error(error, method) @hint = hint @aria_id = "form-field-#{SecureRandom.hex(5)}" super(**attributes) end |
Instance Method Details
#view_template ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/shadcn_phlexcomponents/components/form/form_input.rb', line 34 def view_template(&) vanish(&) @id ||= field_id(@object_name, @method) @name ||= field_name(@object_name, @method) FormField(data: label_and_hint_container_attributes) do render_label(&) Input(type: @type, id: @id, name: @name, value: @value, aria: aria_attributes, **@attributes) render_hint(&) render_error end end |