Class: SimpleFormExtension::Inputs::SelectizeInput
- Inherits:
-
SimpleForm::Inputs::Base
- Object
- SimpleForm::Inputs::Base
- SimpleFormExtension::Inputs::SelectizeInput
- Includes:
- Translations
- Defined in:
- lib/simple_form_extension/inputs/selectize_input.rb
Instance Method Summary collapse
- #collection ⇒ Object
- #creatable? ⇒ Boolean
-
#input(wrapper_options = {}) ⇒ Object
This field only allows local select options (serialized into JSON) Searching for remote ones will be implemented later.
- #max_items ⇒ Object
- #multi? ⇒ Boolean
- #serialized_value ⇒ Object
- #sort_field ⇒ Object
- #value ⇒ Object
Methods included from Translations
Instance Method Details
#collection ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/simple_form_extension/inputs/selectize_input.rb', line 50 def collection if (collection = [:collection]) if enumerable?(collection) collection.map(&method(:serialize_option)) else (object.send(collection) || []).map(&method(:serialize_option)) end elsif relation? reflection.klass.all.map(&method(:serialize_option)) else [] end end |
#creatable? ⇒ Boolean
33 34 35 |
# File 'lib/simple_form_extension/inputs/selectize_input.rb', line 33 def creatable? !![:creatable] end |
#input(wrapper_options = {}) ⇒ Object
This field only allows local select options (serialized into JSON) Searching for remote ones will be implemented later.
Data attributes that may be useful :
:'search-url' => search_url,
:'search-param' => search_param,
:'preload' => preload,
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/simple_form_extension/inputs/selectize_input.rb', line 15 def input( = {}) @attribute_name = foreign_key if relation? [:data] ||= {} [:data].merge!( :'selectize' => true, :'value' => serialized_value, :'creatable' => creatable?, :'multi' => multi?, :'add-translation' => _translate('selectize.add'), :'collection' => collection, :'max-items' => max_items, :'sort-field' => sort_field ) @builder.hidden_field attribute_name, end |
#max_items ⇒ Object
42 43 44 |
# File 'lib/simple_form_extension/inputs/selectize_input.rb', line 42 def max_items [:max_items] end |
#multi? ⇒ Boolean
37 38 39 40 |
# File 'lib/simple_form_extension/inputs/selectize_input.rb', line 37 def multi? (.key?(:multi) && !![:multi]) || enumerable?(value) end |
#serialized_value ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/simple_form_extension/inputs/selectize_input.rb', line 64 def serialized_value if multi? value.map do |item| { text: item, value: item } end else value && { text: value, value: value } end end |
#sort_field ⇒ Object
46 47 48 |
# File 'lib/simple_form_extension/inputs/selectize_input.rb', line 46 def sort_field [:sort_field] ||= 'text' end |
#value ⇒ Object
74 75 76 |
# File 'lib/simple_form_extension/inputs/selectize_input.rb', line 74 def value @value ||= (:value) { object.send(attribute_name) } end |