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

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

Constant Summary collapse

FILE_INPUT_TYPES =

The as: values that render through the Uppy file-upload component — the single source of truth, also consulted by Wizard::Attachments.field? so a wizard can detect an attachment field model-free without re-listing the aliases.

%i[uppy file attachment].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

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.



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

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.



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

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.



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

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

#easymde_tagObject Also known as: markdown_tag



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

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

#flatpickr_tagObject Also known as: datetime_tag, date_tag, time_tag



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

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

#hidden?Boolean

Returns:

  • (Boolean)


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

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

#int_tel_input_tagObject Also known as: phone_tag



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

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

#json_input_tagObject Also known as: json_tag, jsonb_tag



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

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

#key_value_store_tagObject Also known as: hstore_tag, key_value_tag



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

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).



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

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

#resource_select_tag(**attributes) ⇒ Object



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

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



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

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



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

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



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

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



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

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

#toggle_tagObject Also known as: switch_tag



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

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

#uppy_tagObject



83
84
85
# File 'lib/plutonium/ui/form/base.rb', line 83

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.



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

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