I'd like to generate check box with custom html attributes (to use UJS later). Here is my view code
<%= check_box_tag "data-toggle-completed" => "" %>
it gives me
<input id="__data-toggle-completed______" name="{"data-toggle-completed"=>""}" type="checkbox" value="1">
But I wanted
<input type="checkbox" data-toggle-completed="">
How can I achieve this?
You must give the custom attributes as fourth arguments, options. The first three arguments are name, value = "1", checked = false. See check_box_tag.
The code could be like this:
<%= check_box_tag :name, 1, false, data: { "toggle-completed" => "" } %>
I was using stimulus js so for custom data-action attribute I did the following
<%= check_box_tag :select_shipping_address, true , true, data:{action:"change->form#show_form"}%>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With