Sha256: aa7ee3ba7718870763eddbe45a64eea953003cc19095a1f027d702ed81c63bd0
Contents?: true
Size: 1.08 KB
Versions: 1
Compression:
Stored size: 1.08 KB
Contents
module Select2 class FieldController < Volt::ModelController def index_ready `$(#{first_element}).select2(#{settings_from_attrs})` end def multiple_ready `$(#{first_element}).select2(#{settings_from_attrs})` end private def options attrs.options.then do |options| if options[0].is_a?(Hash) options_hash = options else options_hash = options.collect { |option| {value: option, label: option } } end options_hash end end def settings_from_attrs settings = `{}` `settings.placeholder = #{attrs.placeholder}` `settings.allowClear = true` if attrs.include_blank settings end def html_class classes = attrs.html_class.split(/\s+/) classes.uniq.join(' ') end def selected_value attrs.value.to_s end def selected_values if attrs.value.is_a?(String) attrs.value.split(/\s+,\s+/) else attrs.value.to_a end end def include_blank? attrs.include_blank ? true : false end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
volt-select2-0.1.0 | app/select2/controllers/field_controller.rb |