jquery - How to make Select2 work with dependent form in rails? -


I have "selection country" and "select city" form, if there is no value for "select country" , Then it shows "Please select country" text, when I selected the country, it will be loaded with "city selection". This works fine, however, when I try to use select2 jquery, Select2 only works with the "select country" form, but this will not apply to the "Select city" form.

This is my code: _form.html in Erb

  & lt; Div class = "field" & gt; & Lt;% = f.label: Country% & gt; & Lt; Br> & Lt;% = f.country_select: Country, Priority:% w {TH SG MY}, hint: "Please select country"%> & Lt; / Div & gt; & Lt; Div class = "field" & gt; & Lt;% = f.label: City% & gt; & Lt; Br / & gt; & Lt;% = Partial render: 'suburban_style', local: {parent_region: f.object.country}%> & Lt; / Div & gt; _subregion_select.html in  

ARB

  & lt; Div id = "subregion-field" & gt; & Lt;% parent_region || = Param [: parent_pear]%> & Lt;% country = Carmen :: Countrycode (parent_manians)% & gt; & Lt;% if country.nil? & Gt%; & Lt; Em> Please select a country above & lt; / Em> & Lt;% elsif country.subregions? & Gt%; & Lt;% = subregion_select (: addresses,: city, parent_commission)% & gt; & Lt;% else% & gt; & Lt;% = text_field (: address, city)% & gt; & Lt;% end% & gt; & Lt; / Div & gt;  

addresses.js.coffee

  $ - & gt; $ (Select "select # select an address, select # address_city") .2 width: '250px' $ ('Choose #Account'). Change (event) - & gt; Country = $ (this) .val () url = "/ addresses / subregion_options? Parent_region = # {$ ('inactive', true) $ ('select', select_wrapper) $ $ ('# subregion-field') $. Country} "select_wrapper.load (url) $ ('select # local'). Change (event) - & gt; $ (@) Closest ('form'). Submit ()  

Thank you very much for your reply.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -