Reputation: 149
So I have multiple checkboxes made using simple form a Ruby Gem. But the issue is that they are not appearing checked even when I have checked and set them "true" and pressed the update button. I have three examples, all of them do not work, and I have tried doing different code for all three.
<%= f.input :same_as_client_email,
inline_label: "Same as Client Email",
as: :boolean %>
The first example
<%= f.input :same_as_client_name,
inline_label: "Same as Client Name",
as: :boolean, checked_value: true,unchecked_value: false
%>
Second example
<%= f.input :active,
as: :boolean,
checked_value: true, unchecked_value: false,
input_html: { value: '1', checked: true },
inline_label: "Active"%>
Final example.
None of these actual work or stay checked. I have other inputs and they are saving when I press the update button. But the check boxes are not. Any help would be appreciated.
Upvotes: 2
Views: 1296
Reputation: 149
It was a javascript problem just in case anyone else comes along and sees this. Be carful using jquery and simpleform together. My problem was that we had jquery code to make our buttons more aesthetically appealing.
//$(function checkbox() {
// 'use strict'
//
// var originalElement = $('input[type="checkbox"]');
// var overlay = '<div class="checkbox-overlay"><div class="inner"></div></div>';
//
// function swapCheckbox() {
// originalElement.replaceWith(overlay);
// }
//
// function toggleCheckbox() {
// $(this).toggleClass('checked');
//
// }
//
// function initialize() {
// swapCheckbox();
// $('body .checkbox-overlay').on('click', toggleCheckbox);
// }
//
// initialize();
//});
But in reality this was making it so simpleform was receiving only 0, and never 1's. In ohter words even if you checked the box it would never actually work because this Jquery code was manipulating the variables as they were sent to simpleform. In the future Ill update this post if i fix the checkboxes so they can look "pretty" while not messing with the functionality. This problem took a long time to solve, considering i was unaware of this file till a SimpleForm developer pointed out their might be a js file messing with my code.
Edit: I hope this explains the problem better!
Upvotes: 1