diff options
author | Madhura Jayaratne <madhura.cj@gmail.com> | 2015-07-06 08:52:26 +0300 |
---|---|---|
committer | Madhura Jayaratne <madhura.cj@gmail.com> | 2015-07-06 09:01:51 +0300 |
commit | 90efc18a701e5de38f53d17132a5aa0c114bc9f2 (patch) | |
tree | d2745453f6c5d0bec3254df36a3a897ad905ce5e /js/export.js | |
parent | 61cbf6b3d99720418dd89c0d503c0faa71f725ef (diff) |
Include unchecked checboxes (which are ignored by serializeArray()) with null and uncheck them when loading the template
Signed-off-by: Madhura Jayaratne <madhura.cj@gmail.com>
Diffstat (limited to 'js/export.js')
-rw-r--r-- | js/export.js | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/js/export.js b/js/export.js index 5d666a4cf2..bbbc74fee4 100644 --- a/js/export.js +++ b/js/export.js @@ -50,6 +50,13 @@ function getTemplateData() } } }); + // include unchecked checboxes (which are ignored by serializeArray()) with null + // to uncheck them when loading the template + $form.find('input[type="checkbox"]:not(:checked)').each(function () { + if (obj[this.name] === undefined) { + obj[this.name] = null; + } + }); return obj; } @@ -118,14 +125,18 @@ function loadTemplate(id) $.each(options, function (key, value) { var $element = $form.find('[name="' + key + '"]'); if ($element.length) { - if (($element.is('input') && $element.attr('type') == 'checkbox') || - ($element.is('input') && $element.attr('type') == 'radio') || - ($element.is('select') && $element.attr('multiple') == 'multiple')) { - if (! value.push) { - value = [value]; + if (($element.is('input') && $element.attr('type') == 'checkbox') && value === null) { + $element.prop('checked', false); + } else { + if (($element.is('input') && $element.attr('type') == 'checkbox') || + ($element.is('input') && $element.attr('type') == 'radio') || + ($element.is('select') && $element.attr('multiple') == 'multiple')) { + if (! value.push) { + value = [value]; + } } + $element.val(value); } - $element.val(value); $element.trigger('change'); } }); |