lokesh-coder / pretty-checkbox

A pure CSS library to beautify checkbox and radio buttons.
https://lokesh-coder.github.io/pretty-checkbox/
MIT License
1.81k stars 151 forks source link

Can't figure out how to reset the checkbox value on page reload #69

Open davidrhoderick opened 5 years ago

davidrhoderick commented 5 years ago

I have a form that has checkboxes and I find them and wrap them with pretty checkboxes like the following:

$gForm.find('.gfield_checkbox li').each(function(index, element) {
  var $checkbox = $(element).find('input[type="checkbox"]'),
      $label = $(element).find('label');

  $label.wrap('<div class="state p-acceptu"></div>');
  $checkbox.wrap('<div class="pretty p-default p-curve p-icon"></div>');

  var $state = $(element).find('.state'),
      $pretty = $(element).find('.pretty');

  $label.wrapInner('<h3></h3>');

  $state.appendTo($pretty);
});

However, when my form has an error on submission and the page is reloaded, ALL the checkboxes are checked. After the variable declaration, I have tried to add $checkbox.removeAttr('checked');, $checkbox.prop('checked', 'false'), and even $checkbox[0].checked = false and every time there is an error in the form, all checkboxes are selected.

So first of all, if my pretty checkboxes are created dynamically and I set the checkbox values before, why are they staying checked? Is there a way I can remove the "checked" property?

I tried looking through the code to find a solution but I can't even really figure out how it works. It seems to just be CSS (generated by SCSS). How come changing the "checked" status does nothing? Surely there is a bug if "checked" property isn't even used; how is it a valid form input if it has no checked value?

davidrhoderick commented 5 years ago

Actually, it looks like pretty checkboxes isn't even checking the inputs at all. They seem to be unlinked and I never get input values for them. Does it have to do with how I dynamically load the display?

I found out that the inputs not sending was due to Gravity Forms behavior; however, I am still unable check or uncheck boxes on a submission with an error that refreshes the page. Is it a bug on Pretty Checkboxes end or is it probably related to Gravity Forms?