Always submit checkboxes that are not checked and force a 0 value (fixes #616)

This commit is contained in:
Djamil Legato
2016-05-31 11:55:56 -07:00
parent 38cff92ae9
commit 636bd157c8
2 changed files with 18 additions and 0 deletions

View File

@@ -20,6 +20,7 @@
* Show page title in Delete Confirmation modal if this information is available
* Don't try to uninstall admin/form/login/email plugins
* Only check for updates if not `admin.maintenance` or `admin.super` [#557](https://github.com/getgrav/grav-plugin-admin/issues/557)
* Always submit checkboxes that are not checked and force a 0 value [#616](https://github.com/getgrav/grav-plugin-admin/issues/616)
# v1.1.0-beta.5
## 05/23/2016

View File

@@ -23,6 +23,7 @@ export default class Form {
this._attachShortcuts();
this._attachToggleables();
this._attachDisabledFields();
this._submitUncheckedFields();
this.observer = new MutationObserver(this.addedNodes);
this.form.each((index, form) => this.observer.observe(form, { subtree: true, childList: true }));
@@ -96,6 +97,22 @@ export default class Form {
});
}
_submitUncheckedFields() {
this.form.on('submit', () => {
let unchecked = this.form.find('input[type="checkbox"]:not(:checked)');
if (!unchecked.length) { return true; }
unchecked.each((index, element) => {
element = $(element);
let name = element.prop('name');
let fake = $(`<input type="hidden" name="${name}" value="0" />`);
this.form.append(fake);
});
return true;
});
}
addedNodes(mutations) {
mutations.forEach((mutation) => {
if (mutation.type !== 'childList' || !mutation.addedNodes) { return; }