Class: Phlexi::Form::Builder
- Inherits:
-
Phlexi::Field::Builder
- Object
- Phlexi::Field::Builder
- Phlexi::Form::Builder
show all
- Includes:
- 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.
36
37
38
39
40
|
# File 'lib/phlexi/form/builder.rb', line 36
def initialize(*, input_attributes: {}, **)
super(*, **)
@input_attributes = input_attributes
end
|
Instance Attribute Details
Returns the value of attribute input_attributes.
26
27
28
|
# File 'lib/phlexi/form/builder.rb', line 26
def input_attributes
@input_attributes
end
|
Instance Method Details
#belongs_to_tag(**options) ⇒ Object
164
165
166
167
168
169
170
171
172
173
|
# File 'lib/phlexi/form/builder.rb', line 164
def belongs_to_tag(**options, &)
options.fetch(:input_param) {
options[:input_param] = if association_reflection.respond_to?(:options) && association_reflection.options[:foreign_key]
association_reflection.options[:foreign_key]
else
:"#{association_reflection.name}_id"
end
}
select_tag(**options, &)
end
|
#boolean_tag ⇒ Object
107
108
109
|
# File 'lib/phlexi/form/builder.rb', line 107
def boolean_tag(**, &)
checkbox_tag(**, theme: :boolean, &)
end
|
Creates a checkbox tag for the field.
103
104
105
|
# File 'lib/phlexi/form/builder.rb', line 103
def checkbox_tag(**, &)
create_component(Components::Checkbox, :checkbox, **, &)
end
|
Creates collection checkboxes for the field.
121
122
123
|
# File 'lib/phlexi/form/builder.rb', line 121
def collection_checkboxes_tag(**, &)
create_component(Components::CollectionCheckboxes, :collection_checkboxes, **, &)
end
|
Creates collection radio buttons for the field.
138
139
140
|
# File 'lib/phlexi/form/builder.rb', line 138
def collection_radio_buttons_tag(**, &)
create_component(Components::CollectionRadioButtons, :collection_radio_buttons, **, &)
end
|
#color_tag ⇒ Object
83
84
85
|
# File 'lib/phlexi/form/builder.rb', line 83
def color_tag(**, &)
input_tag(type: :color, theme: :color, **, &)
end
|
#date_tag ⇒ Object
58
59
60
|
# File 'lib/phlexi/form/builder.rb', line 58
def date_tag(**, &)
input_tag(type: :date, theme: :date, **, &)
end
|
#datetime_local_tag ⇒ Object
Also known as:
datetime_tag
66
67
68
|
# File 'lib/phlexi/form/builder.rb', line 66
def datetime_local_tag(**, &)
input_tag(type: :"datetime-local", theme: :datetime, **, &)
end
|
#email_tag ⇒ Object
71
72
73
|
# File 'lib/phlexi/form/builder.rb', line 71
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
|
111
112
113
|
# File 'lib/phlexi/form/builder.rb', line 111
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(**options) ⇒ Object
Also known as:
has_and_belongs_to_many_tag
185
186
187
188
189
190
191
|
# File 'lib/phlexi/form/builder.rb', line 185
def has_many_tag(**options, &)
options.fetch(:input_param) {
options[:input_param] = :"#{association_reflection.name.to_s.singularize}_ids"
}
select_tag(**options, &)
end
|
#has_one_tag ⇒ Object
181
182
183
|
# File 'lib/phlexi/form/builder.rb', line 181
def has_one_tag(**, &)
raise NotImplementedError, "has_one associations are NOT supported"
end
|
95
96
97
|
# File 'lib/phlexi/form/builder.rb', line 95
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
151
152
153
154
|
# File 'lib/phlexi/form/builder.rb', line 151
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.
46
47
48
|
# File 'lib/phlexi/form/builder.rb', line 46
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
54
55
56
|
# File 'lib/phlexi/form/builder.rb', line 54
def number_tag(**, &)
input_tag(type: :number, theme: :number, **, &)
end
|
#password_tag ⇒ Object
75
76
77
|
# File 'lib/phlexi/form/builder.rb', line 75
def password_tag(**, &)
input_tag(type: :password, theme: :password, **, &)
end
|
#phone_tag ⇒ Object
79
80
81
|
# File 'lib/phlexi/form/builder.rb', line 79
def phone_tag(**, &)
input_tag(type: :tel, theme: :phone, **, &)
end
|
#polymorphic_belongs_to_tag ⇒ Object
175
176
177
178
179
|
# File 'lib/phlexi/form/builder.rb', line 175
def polymorphic_belongs_to_tag(**, &)
raise NotImplementedError, "polymorphic belongs_to associations are not YET supported"
end
|
Creates a radio button tag for the field.
129
130
131
|
# File 'lib/phlexi/form/builder.rb', line 129
def radio_button_tag(**, &)
create_component(Components::RadioButton, :radio, **, &)
end
|
#search_tag ⇒ Object
91
92
93
|
# File 'lib/phlexi/form/builder.rb', line 91
def search_tag(**, &)
input_tag(type: :search, theme: :search, **, &)
end
|
Creates a select tag for the field.
160
161
162
|
# File 'lib/phlexi/form/builder.rb', line 160
def select_tag(**, &)
create_component(Components::Select, :select, **, &)
end
|
#string_tag ⇒ Object
50
51
52
|
# File 'lib/phlexi/form/builder.rb', line 50
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.
146
147
148
|
# File 'lib/phlexi/form/builder.rb', line 146
def textarea_tag(**, &)
create_component(Components::Textarea, :textarea, **, &)
end
|
#time_tag ⇒ Object
62
63
64
|
# File 'lib/phlexi/form/builder.rb', line 62
def time_tag(**, &)
input_tag(type: :time, theme: :time, **, &)
end
|
#url_tag ⇒ Object
87
88
89
|
# File 'lib/phlexi/form/builder.rb', line 87
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
|