i've been developing a rails application for my work, and i wonder how to use coffee script to make my form dynamic.
Here is a sample of my _form.html.erb:
<tr>
<td>
<strong class="col-md-3">L'OCS est-il maintenu ?</strong>
<div class="col-md-3">
<%= f.check_box :maintenance, label: "", :class => 'towatch' %>
</div>
<strong class="col-md-2">TMA</strong>
<div class="col-md-3">
<%= f.collection_select(:tma_id, Entity.all.order(:name), :id, :name, prompt: 'Choisissez une TMA', :class => 'toset', hide_label: true) %>
</div>
</td>
</tr>
I want to make the collection accessible only, if the checkbook is checked.
Here is my coffee script :
# Display if already checked
if $(".towatch:checked")
$(".toset").toggle()
# Toggle on change
$(".towatch").change ->
$(".toset").toggle()
This coffee script doesn't work. Can someone explain me why, and how to make it works ?