Class: Ecoportal::API::GraphQL::Base::Page::DataField::Select
- Inherits:
-
DataField
- Object
- DataField
- Ecoportal::API::GraphQL::Base::Page::DataField::Select
- Defined in:
- lib/ecoportal/api/graphql/base/page/data_field/select.rb
Instance Method Summary collapse
- #as_input ⇒ Object
-
#clear_selection ⇒ Object
Deselect all options.
-
#select_option(*id_or_values) ⇒ Object
Select an option by id, name, or value.
- #selected_options ⇒ Object
Instance Method Details
#as_input ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ecoportal/api/graphql/base/page/data_field/select.rb', line 27 def as_input return nil unless dirty? { select: { id: id, # rubocop:disable Style/DoubleNegation options: (doc['options'] || []).map { |opt| { id: opt['id'], selected: !!opt['selected'] } } # rubocop:enable Style/DoubleNegation } } end |
#clear_selection ⇒ Object
Deselect all options.
19 20 21 |
# File 'lib/ecoportal/api/graphql/base/page/data_field/select.rb', line 19 def clear_selection (doc['options'] || []).each { |opt| opt['selected'] = false } end |
#select_option(*id_or_values) ⇒ Object
Select an option by id, name, or value. Deselects all others (single-select). For multi-select fields, call with multiple values.
9 10 11 12 13 14 15 16 |
# File 'lib/ecoportal/api/graphql/base/page/data_field/select.rb', line 9 def select_option(*id_or_values) targets = id_or_values.flatten.map(&:to_s) (doc['options'] || []).each do |opt| opt['selected'] = targets.include?(opt['id'].to_s) || targets.include?(opt['name'].to_s) || targets.include?(opt['value'].to_s) end end |
#selected_options ⇒ Object
23 24 25 |
# File 'lib/ecoportal/api/graphql/base/page/data_field/select.rb', line 23 def (doc['options'] || []).select { |opt| opt['selected'] } end |