Class: Plutonium::UI::Form::Base::Builder

Inherits:
Builder
  • Object
show all
Includes:
Phlexi::Field::Common::Tokens, Component::ResolvesTags, Options::InferredTypes
Defined in:
lib/plutonium/ui/form/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Component::ResolvesTags

#component_for

Constructor Details

#initialize(*args, as: nil, **kwargs, &block) ⇒ Builder

Consume :as here so it doesn't land in Phlexi's @options:as is a Plutonium-internal concept (it picks the tag method), not a Phlexi field option.



17
18
19
20
# File 'lib/plutonium/ui/form/base.rb', line 17

def initialize(*args, as: nil, **kwargs, &block)
  @as = as
  super(*args, **kwargs, &block)
end

Instance Attribute Details

#asObject (readonly)

Returns the value of attribute as.



22
23
24
# File 'lib/plutonium/ui/form/base.rb', line 22

def as
  @as
end

Instance Method Details

#currency_tagObject

Money input: a number field with an optional currency-unit prefix. See Components::Currency for how the unit resolves.



69
70
71
# File 'lib/plutonium/ui/form/base.rb', line 69

def currency_tag(**, &)
  create_component(Components::Currency, :currency, **, &)
end

#easymde_tagObject Also known as: markdown_tag



41
42
43
# File 'lib/plutonium/ui/form/base.rb', line 41

def easymde_tag(**, &)
  create_component(Plutonium::UI::Form::Components::Easymde, :easymde, **, &)
end

#flatpickr_tagObject Also known as: datetime_tag, date_tag, time_tag



63
64
65
# File 'lib/plutonium/ui/form/base.rb', line 63

def flatpickr_tag(**, &)
  create_component(Components::Flatpickr, :flatpickr, **, &)
end

#hidden?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/plutonium/ui/form/base.rb', line 24

def hidden?
  as.to_s == "hidden"
end

#int_tel_input_tagObject Also known as: phone_tag



73
74
75
# File 'lib/plutonium/ui/form/base.rb', line 73

def int_tel_input_tag(**, &)
  create_component(Components::IntlTelInput, :int_tel_input, **, &)
end

#json_input_tagObject Also known as: json_tag, jsonb_tag



93
94
95
# File 'lib/plutonium/ui/form/base.rb', line 93

def json_input_tag(**, &)
  create_component(Components::Json, :json, **, &)
end

#key_value_store_tagObject Also known as: hstore_tag, key_value_tag



89
90
91
# File 'lib/plutonium/ui/form/base.rb', line 89

def key_value_store_tag(**, &)
  create_component(Components::KeyValueStore, :key_value_store, **, &)
end

#password_tagObject

Password / secret input that never renders the stored value. Routed to here for both explicit as: :password and every field inferred as a password (see Options::InferredTypes#infer_field_component).



54
55
56
# File 'lib/plutonium/ui/form/base.rb', line 54

def password_tag(**, &)
  create_component(Components::Password, :password, **, &)
end

#resource_select_tag(**attributes) ⇒ Object



97
98
99
100
101
102
103
104
105
# File 'lib/plutonium/ui/form/base.rb', line 97

def resource_select_tag(**attributes, &)
  attributes[:data_controller] = tokens(attributes[:data_controller], "slim-select")
  # class!: "" clears the underlying <select>'s themed classes
  # (pu-input etc.) — the visible element is slim-select's
  # generated .ss-main, so leaving Tailwind input chrome on the
  # native select can leak into chip layout (e.g. forcing
  # flex-direction: column or w-full on multi-mode chips).
  create_component(Components::ResourceSelect, :select, class!: "", **attributes, &)
end

#secure_association_tag(**attributes) ⇒ Object Also known as: belongs_to_tag, has_many_tag, has_one_tag, association_tag



107
108
109
110
# File 'lib/plutonium/ui/form/base.rb', line 107

def secure_association_tag(**attributes, &)
  attributes[:data_controller] = tokens(attributes[:data_controller], "slim-select") # TODO: put this behind a config
  create_component(Components::SecureAssociation, :association, **attributes, &)
end

#secure_polymorphic_association_tag(**attributes) ⇒ Object Also known as: polymorphic_belongs_to_tag



120
121
122
123
# File 'lib/plutonium/ui/form/base.rb', line 120

def secure_polymorphic_association_tag(**attributes, &)
  attributes[:data_controller] = tokens(attributes[:data_controller], "slim-select") # TODO: put this behind a config
  create_component(Components::SecurePolymorphicAssociation, :polymorphic_association, **attributes, &)
end

#slim_select_tag(**attributes) ⇒ Object



58
59
60
61
# File 'lib/plutonium/ui/form/base.rb', line 58

def slim_select_tag(**attributes, &)
  attributes[:data_controller] = tokens(attributes[:data_controller], "slim-select")
  select_tag(**attributes, required: false, class!: "", &)
end

#textarea_tag(**attributes) ⇒ Object Also known as: text_tag



36
37
38
39
# File 'lib/plutonium/ui/form/base.rb', line 36

def textarea_tag(**attributes, &)
  attributes[:data_controller] = tokens(attributes[:data_controller], "textarea-autogrow")
  super
end

#toggle_tagObject Also known as: switch_tag



46
47
48
# File 'lib/plutonium/ui/form/base.rb', line 46

def toggle_tag(**, &)
  create_component(Plutonium::UI::Form::Components::Toggle, :toggle, **, &)
end

#uppy_tagObject



78
79
80
# File 'lib/plutonium/ui/form/base.rb', line 78

def uppy_tag(**, &)
  create_component(Components::Uppy, :uppy, **, &)
end

#wrappedObject

Hidden fields (form.field(name, as: :hidden)) skip the label / hint / error chrome and render inside a <div hidden> so they're also excluded from CSS Grid / Flex layout.



31
32
33
34
# File 'lib/plutonium/ui/form/base.rb', line 31

def wrapped(**, &)
  return Plutonium::UI::Form::Components::HiddenWrapper.new(self, &) if hidden?
  super
end