Class: Superform::Rails::Components::SelectField
Instance Attribute Summary
#dom, #field
Instance Method Summary
collapse
#field_attributes
#field_attributes, #focus
Constructor Details
#initialize(collection: []) ⇒ SelectField
Returns a new instance of SelectField.
335
336
337
338
|
# File 'lib/superform/rails.rb', line 335
def initialize(*, collection: [], **, &)
super(*, **, &)
@collection = collection
end
|
Instance Method Details
#blank_option ⇒ Object
354
355
356
|
# File 'lib/superform/rails.rb', line 354
def blank_option(&)
option(selected: field.value.nil?, &)
end
|
#false_option ⇒ Object
362
363
364
|
# File 'lib/superform/rails.rb', line 362
def false_option(&)
option(selected: field.value == false, value: false.to_s, &)
end
|
#options(*collection) ⇒ Object
348
349
350
351
352
|
# File 'lib/superform/rails.rb', line 348
def options(*collection)
map_options(collection).each do |key, value|
option(selected: field.value == key, value: key) { value }
end
end
|
#true_option ⇒ Object
358
359
360
|
# File 'lib/superform/rails.rb', line 358
def true_option(&)
option(selected: field.value == true, value: true.to_s, &)
end
|
#view_template(&options) ⇒ Object
340
341
342
343
344
345
346
|
# File 'lib/superform/rails.rb', line 340
def view_template(&options)
if block_given?
select(**attributes, &options)
else
select(**attributes) { options(*@collection) }
end
end
|