Class: Phlexi::Form::Builder
- Inherits:
-
Phlexi::Field::Builder
- Object
- Phlexi::Field::Builder
- Phlexi::Form::Builder
show all
- Includes:
- Phlexi::Field::Common::Tokens, HTML::Behaviour, Options::Autofocus, Options::Choices, Options::Disabled, Options::Errors, Options::Hints, Options::InferredTypes, Options::Length, Options::Limit, Options::Max, Options::Min, Options::Pattern, Options::Readonly, Options::Required, Options::Step, Options::Validators
- Defined in:
- lib/phlexi/form/builder.rb
Overview
Builder class is responsible for building form fields with various options and components.
Defined Under Namespace
Classes: FieldCollection
Instance Attribute Summary collapse
Instance Method Summary
collapse
#step
#limit
#pattern
#min
#max
#maxlength, #minlength
#readonly!, #readonly?
#disabled!, #disabled?
#focused!, #focused?
#required!, #required?
#show_hint?
#choices
#can_show_errors?, #custom_error, #error, #full_error, #has_errors?, #object_valid?, #show_errors?, #valid?
Constructor Details
#initialize(input_attributes: {}) ⇒ Builder
Initializes a new Builder instance.
37
38
39
40
41
|
# File 'lib/phlexi/form/builder.rb', line 37
def initialize(*, input_attributes: {}, **)
super(*, **)
@input_attributes = input_attributes
end
|
Instance Attribute Details
Returns the value of attribute input_attributes.
27
28
29
|
# File 'lib/phlexi/form/builder.rb', line 27
def input_attributes
@input_attributes
end
|
Instance Method Details
#belongs_to_tag ⇒ Object
175
176
177
|
# File 'lib/phlexi/form/builder.rb', line 175
def belongs_to_tag(**, &)
create_component(Components::BelongsTo, :belongs_to, **, &)
end
|
#boolean_tag ⇒ Object
109
110
111
|
# File 'lib/phlexi/form/builder.rb', line 109
def boolean_tag(**, &)
checkbox_tag(**, theme: :boolean, &)
end
|
Creates a checkbox tag for the field.
105
106
107
|
# File 'lib/phlexi/form/builder.rb', line 105
def checkbox_tag(**, &)
create_component(Components::Checkbox, :checkbox, **, &)
end
|
Creates collection checkboxes for the field.
131
132
133
|
# File 'lib/phlexi/form/builder.rb', line 131
def collection_checkboxes_tag(**, &)
create_component(Components::CollectionCheckboxes, :collection_checkboxes, **, &)
end
|
Creates collection radio buttons for the field.
149
150
151
|
# File 'lib/phlexi/form/builder.rb', line 149
def collection_radio_buttons_tag(**, &)
create_component(Components::CollectionRadioButtons, :collection_radio_buttons, **, &)
end
|
#color_tag ⇒ Object
84
85
86
|
# File 'lib/phlexi/form/builder.rb', line 84
def color_tag(**, &)
input_tag(type: :color, theme: :color, **, &)
end
|
#date_tag ⇒ Object
59
60
61
|
# File 'lib/phlexi/form/builder.rb', line 59
def date_tag(**, &)
input_tag(type: :date, theme: :date, **, &)
end
|
#datetime_local_tag ⇒ Object
Also known as:
datetime_tag
67
68
69
|
# File 'lib/phlexi/form/builder.rb', line 67
def datetime_local_tag(**, &)
input_tag(type: :"datetime-local", theme: :datetime, **, &)
end
|
#email_tag ⇒ Object
72
73
74
|
# File 'lib/phlexi/form/builder.rb', line 72
def email_tag(**, &)
input_tag(type: :email, theme: :email, **, &)
end
|
Creates an error tag for the field.
218
219
220
|
# File 'lib/phlexi/form/builder.rb', line 218
def error_tag(**, &)
create_component(Components::Error, :error, **, &)
end
|
250
251
252
253
254
|
# File 'lib/phlexi/form/builder.rb', line 250
def (params)
raise "field##{dom.name} did not define an input component" unless @field_input_extractor
@field_input_extractor.(params)
end
|
113
114
115
|
# File 'lib/phlexi/form/builder.rb', line 113
def file_input_tag(**, &)
create_component(Components::FileInput, :file, **, &)
end
|
Creates a full error tag for the field.
226
227
228
|
# File 'lib/phlexi/form/builder.rb', line 226
def full_error_tag(**, &)
create_component(Components::FullError, :full_error, **, &)
end
|
256
257
258
|
# File 'lib/phlexi/form/builder.rb', line 256
def has_file_input!
parent.has_file_input!
end
|
#has_many_tag ⇒ Object
Also known as:
has_and_belongs_to_many_tag
189
190
191
|
# File 'lib/phlexi/form/builder.rb', line 189
def has_many_tag(**, &)
create_component(Components::HasMany, :has_many, **, &)
end
|
#has_one_tag ⇒ Object
185
186
187
|
# File 'lib/phlexi/form/builder.rb', line 185
def has_one_tag(**, &)
raise NotImplementedError, "has_one associations are NOT supported"
end
|
96
97
98
|
# File 'lib/phlexi/form/builder.rb', line 96
def hidden_input_tag(**, &)
input_tag(type: :hidden, theme: nil, **, &)
end
|
Creates a hint tag for the field.
210
211
212
|
# File 'lib/phlexi/form/builder.rb', line 210
def hint_tag(**, &)
create_component(Components::Hint, :hint, **, &)
end
|
#hstore_tag ⇒ Object
162
163
164
165
|
# File 'lib/phlexi/form/builder.rb', line 162
def hstore_tag(**, &)
@value = @value.to_s.tr("{}", "")
textarea_tag(**, theme: :hstore, &)
end
|
194
195
196
|
# File 'lib/phlexi/form/builder.rb', line 194
def input_array_tag(**, &)
create_component(Components::InputArray, :array, **, &)
end
|
Creates an input tag for the field.
47
48
49
|
# File 'lib/phlexi/form/builder.rb', line 47
def input_tag(theme: :input, **, &)
create_component(Components::Input, theme, **, &)
end
|
Creates a label tag for the field.
202
203
204
|
# File 'lib/phlexi/form/builder.rb', line 202
def label_tag(**, &)
create_component(Components::Label, :label, **, &)
end
|
#number_tag ⇒ Object
55
56
57
|
# File 'lib/phlexi/form/builder.rb', line 55
def number_tag(**, &)
input_tag(type: :number, theme: :number, **, &)
end
|
#password_tag ⇒ Object
76
77
78
|
# File 'lib/phlexi/form/builder.rb', line 76
def password_tag(**, &)
input_tag(type: :password, theme: :password, **, &)
end
|
#phone_tag ⇒ Object
80
81
82
|
# File 'lib/phlexi/form/builder.rb', line 80
def phone_tag(**, &)
input_tag(type: :tel, theme: :phone, **, &)
end
|
#polymorphic_belongs_to_tag ⇒ Object
179
180
181
182
183
|
# File 'lib/phlexi/form/builder.rb', line 179
def polymorphic_belongs_to_tag(**, &)
raise NotImplementedError, "polymorphic belongs_to associations are not YET supported"
end
|
Creates a radio button tag for the field.
139
140
141
|
# File 'lib/phlexi/form/builder.rb', line 139
def radio_button_tag(**, &)
create_component(Components::RadioButton, :radio_button, **, &)
end
|
Creates a checkbox tag for the field.
122
123
124
|
# File 'lib/phlexi/form/builder.rb', line 122
def range_tag(**, &)
create_component(Components::Range, :range, **, &)
end
|
#search_tag ⇒ Object
92
93
94
|
# File 'lib/phlexi/form/builder.rb', line 92
def search_tag(**, &)
input_tag(type: :search, theme: :search, **, &)
end
|
Creates a select tag for the field.
171
172
173
|
# File 'lib/phlexi/form/builder.rb', line 171
def select_tag(**, &)
create_component(Components::Select, :select, **, &)
end
|
#string_tag ⇒ Object
51
52
53
|
# File 'lib/phlexi/form/builder.rb', line 51
def string_tag(**, &)
input_tag(type: :text, theme: :string, **, &)
end
|
246
247
248
|
# File 'lib/phlexi/form/builder.rb', line 246
def submit_button_tag(**, &)
create_component(Components::SubmitButton, :submit_button, **, &)
end
|
Creates a textarea tag for the field.
157
158
159
|
# File 'lib/phlexi/form/builder.rb', line 157
def textarea_tag(**, &)
create_component(Components::Textarea, :textarea, **, &)
end
|
#time_tag ⇒ Object
63
64
65
|
# File 'lib/phlexi/form/builder.rb', line 63
def time_tag(**, &)
input_tag(type: :time, theme: :time, **, &)
end
|
#url_tag ⇒ Object
88
89
90
|
# File 'lib/phlexi/form/builder.rb', line 88
def url_tag(**, &)
input_tag(type: :url, theme: :url, **, &)
end
|
#wrapped(inner: {}, **attributes) {|block| ... } ⇒ Components::Wrapper
Wraps the field with additional markup.
236
237
238
239
240
|
# File 'lib/phlexi/form/builder.rb', line 236
def wrapped(inner: {}, **attributes, &)
attributes = apply_component_theme(attributes, :wrapper)
inner = apply_component_theme(inner, :inner_wrapper)
Components::Wrapper.new(self, inner: inner, **attributes, &)
end
|