ruby on rails - Coffeescript evaluates only once -


i want make select checkbox based on this findle. made coffeescript this:

$(document).on 'click','.select_all_clans', ->   if $(this).is(':checked')     $('.clan_checkbox').attr 'checked', true 

but works when check_box.clan_checkbox not selected earlier, , checks them once.

this form:

<%= form_tag show_schools_path %>  <p>    wybierz klan/y:     feniks: <%= check_box_tag 'clans[]','feniks', (true if !@clans.nil? , @clans.include? 'feniks'), class: "clan_checkbox" %>,    jednorożec: <%= check_box_tag 'clans[]','jednorożec', (true if !@clans.nil? , @clans.include? 'jednorożec'), class: "clan_checkbox" %>,    krab: <%= check_box_tag 'clans[]', 'krab', (true if !@clans.nil? , @clans.include? 'krab'), class: "clan_checkbox" %>,    lew: <%= check_box_tag 'clans[]', 'lew', (true if !@clans.nil? , @clans.include? 'lew'), class: "clan_checkbox" %>,    zaznacz wszystkie: <%= check_box_tag 'select_all', 'nil', false, class: "select_all_clans" %>  </p> <%= submit_tag "szukaj!" %> <% end %> 

i think becouse of (true if !@clans.nil? , @clans.include? 'lew')evaluation.

i starting learning cs pleasemake full explain if possible :)

here go, hope looking for:

boxes = $('#checkboxlist [type=checkbox]') selectall = $('.selectall')     togglecheckboxes = ->         if $(this).is ':checked' boxes.prop "checked", true else boxes.prop "checked", false  selectall.on 'click', togglecheckboxes 

fiddle

you should change attr() prop().

nothing special happening here, have bound togglecheckboxes() click event on selectall element.

tip: next time add javascript tag issues this, you'll solution faster , u can convert cs later.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -