jquery ui - Select2 placeholder not working in rails app with hidden_field -


haml:

 .form-group             = f.hidden_field :gender, :id => 'select2', :style => "width:100%; height: 40px" 

js:

 $("#select2").select2({     createsearchchoice: function (term, data) {       if ($(data).filter(function () {             return this.text.localecompare(term) === this.text;           }).length === 0) {         return {           id: term,           text: term         };       }       console.log('select2', $("#select2").data.text);     },     placeholder: "enter custom gender or select 1 below",     multiple: false,     data: [{       id: 'male',       text: 'male'     }, {       id: 'female',       text: 'female'     }, {       id: 'custom',       text: 'custom'     }] }); 

select2 doing need now, placeholder not showing on view. help, appreciated.

i have written small coffee script things normal auto-complete thing plus pre-filled data

$(document).ready ->   $('.select2').each (i, e) =>     select = $(e)     options =       placeholder: select.data('placeholder')       minimuminputlength: 1      if select.hasclass('ajax') # add ajax functionality if class present       options.ajax =         url: select.data('source')         quietmillis: 100         datatype: 'json'         data: (term) ->           q: term         results: (data) ->           results: data.resources           more: false        options.dropdowncssclass = "bigdrop"       options.initselection = (element, callback) ->         callback({ text: element.attr('data-value') })     select.select2(options) 

and hidden field this

hidden_field_tag(:search, '', id: 'res_select', class: 'select2 ajax form-control select-overide', style: 'width: 100%;', data: { source: "/products/autocomplete", placeholder: 'search name' }, :value=> params["search"], "data-value" => params['search']) 

try work.


Comments