From 636bd157c836c9f070c49d918e415f9795828ce4 Mon Sep 17 00:00:00 2001 From: Djamil Legato Date: Tue, 31 May 2016 11:55:56 -0700 Subject: [PATCH] Always submit checkboxes that are not checked and force a 0 value (fixes #616) --- CHANGELOG.md | 1 + themes/grav/app/forms/form.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7100879..fffa3246 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/themes/grav/app/forms/form.js b/themes/grav/app/forms/form.js index 15c3a5d9..d0020015 100644 --- a/themes/grav/app/forms/form.js +++ b/themes/grav/app/forms/form.js @@ -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 = $(``); + this.form.append(fake); + }); + + return true; + }); + } + addedNodes(mutations) { mutations.forEach((mutation) => { if (mutation.type !== 'childList' || !mutation.addedNodes) { return; }