0
votes

I need to toggle boolean value through one checkbox

Right now I have two checkboxes one set to true and the other set to false

When someone clicks on wither button it set an event on the submit button to submit the new value.

<%= form_with(model: @project, local: true) do |form| %>
<div>
    <div id="info_false">
        <%= label :access_rights, "Pending", value: false %>
        <%= form.radio_button :build_one, false, :checked => true, :value => false, id: "build_one_1" %>
    </div>
    <div id="info_true">
        <%= label :access_rights, "Completed", value: true %>
        <%= form.radio_button :build_one, true, :value => true, id: "build_one_2" %>
    </div>
</div>

<div class="actions">
<%= form.submit id: "build_one", :style => "visibility:hidden;", data: { confirm: "Are you sure?"} %>
</div>

enter image description here enter image description here

1
What is your question ? - Subash
I need to toggle a boolean value through one checkbox - right now I have two checkboxes one set to true and one set to false. So when the one checkbox is not checked it will be false and when checked it will be true. - James Brown

1 Answers

1
votes

Those are radio buttons not checkboxes, I'm not sure if I understand what you are looking for but you can toggle between true or false values for radio buttons in a simple way

Demo https://jsfiddle.net/ff9ccqx5/1/