1

I am using on my pages client_side_validation and everything works fine. But now I have in my form 2 checkboxes and I need to check the user fill one of them (I used jQuery for denied to fill both).

I am trying to fing the way, how to do validation rule in my model for getting, that the checkbox was filled.

If I want to check my input (if contains some string), I'll use:

validates_presence_of :email, :message => "Some message"

But I don't know, how to do the same for checkbox... In my form is:

  <div class="field">
    <%= f.label :item %><br />
    Val_A: <%= f.check_box :item, :value => 0, :checked => @data.item == 0, :class => 'checkboxes'%>
    Val_B: <%= f.check_box :item, :value => 1, :checked => @data.item == 1, :class => 'checkboxes' %>
  </div>

Thank you so much

4

1 に答える 1

1

2 つのオプションのうち 1 つだけが選択されるようにする場合は、チェックボックスではなくラジオ ボタンを使用する必要があります。

于 2012-07-19T15:22:18.287 に答える