jquery_remember_state
jquery_remember_state copied to clipboard
save/restoreState does not take unchecked checkboxes into account
When saving state, I noticed that checkboxes that are not checked are not saved, and therefore, not restored. The following changes against version 1.4.1 fix this (sorry, I am not able to generate a proper full diff):
@@ -49,8 +49,12 @@ if ($e.is(":radio")) { $e.filter("[value=\"" + data[i].value + "\"]").prop("checked", true); } - else if ($e.is(":checkbox") && data[i].value) { - $e.prop("checked", true); + else if ($e.is(":checkbox")) { + if (data[i].value) { + $e.prop("checked", true); + } else { + $e.prop("checked", false); + } } else if ($e.is("select")) { $e.find("[value=\"" + data[i].value + "\"]").prop("selected", true);
and
@@ -95,6 +98,14 @@ var $i = $(this); values.push({ name: $i.attr("name"), value: $i.val() }); }); + // Checkbox that are not selected are ignored, so we need to add them + instance.$el.find("input[type='checkbox']").each(function() { + var $i = $(this); + if ($i.is(":checked") == false) { + values.push({ name: $i.attr("name"), value: $i.is(":checked") }); + } + }); + values = instance.removeIgnored(values); values.length && internals.setObject(instance.objName, values); },