lots of frameworks generate an <input type="hidden" name="check" value="default"> directly before the checkbox when using a checkbox. This leads to a problem with this plugin: it assumes that the checkbox isn't a multi plugin and its value is always the default value.
I did the following patch to get it working:
@@ -88,16 +88,19 @@
elType = el.attr("type");
multi = contains(multiInputs, elType);
- if (!multi) { return el.val(); }
+ if (!multi && (el.length < 1 || $(el[0]).attr('type') != 'hidden')) { return el.val(); }
if (elType === "radio") { return el.filter(":checked").val(); }
- if (elType === "checkbox") {
- checkVals = $.map(el.filter(":checked"), function (checkbox) {
- return $(checkbox).val();
- });
- return checkVals;
+ checkVals = $.map(el.filter(":checked"), function (checkbox) {
+ return $(checkbox).val();
+ });
+
+ if($(el[0]).attr("type") == 'hidden' && checkVals.length === 0) {
+ checkVals = [$(el[0]).val()];
}
+
+ return checkVals;
}
// Event handler for when a toggling element changes value.
This is not the most beautiful solution, but at least it works.
lol @ckruse messy code alright, but watever gets the code working 👍
Wrote a similar plugin, will be sharing it on my page soon https://marcus-hiles.com/
Hey,
lots of frameworks generate an
<input type="hidden" name="check" value="default">
directly before the checkbox when using a checkbox. This leads to a problem with this plugin: it assumes that the checkbox isn't a multi plugin and its value is always the default value.I did the following patch to get it working:
This is not the most beautiful solution, but at least it works.