samedi 30 mai 2015

Coffeescript evaluates only once

I want to make a select all checkbox based on this findle. I made a coffeescript like this:

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

But it works only when the check_box.clan_checkbox was not selected earlier, and it checks them only once.

This is my form:

<%= form_tag show_schools_path do %>
 <p>
   Wybierz klan/y: 
   Feniks: <%= check_box_tag 'clans[]','Feniks', (true if !@clans.nil? and @clans.include? 'Feniks'), class: "clan_checkbox" %>,
   Jednorożec: <%= check_box_tag 'clans[]','Jednorożec', (true if !@clans.nil? and @clans.include? 'Jednorożec'), class: "clan_checkbox" %>,
   Krab: <%= check_box_tag 'clans[]', 'Krab', (true if !@clans.nil? and @clans.include? 'Krab'), class: "clan_checkbox" %>,
   Lew: <%= check_box_tag 'clans[]', 'Lew', (true if !@clans.nil? and @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 this is becouse of this (true if !@clans.nil? and @clans.include? 'Lew')evaluation.

I am just starting learning CS so pleasemake full explain if possible :)




Aucun commentaire:

Enregistrer un commentaire