Skip to content

Commit

Permalink
Include unchecked checboxes (which are ignored by serializeArray()) w…
Browse files Browse the repository at this point in the history
…ith null and uncheck them when loading the template

Signed-off-by: Madhura Jayaratne <madhura.cj@gmail.com>
  • Loading branch information
madhuracj committed Jul 6, 2015
1 parent 61cbf6b commit 90efc18
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions js/export.js
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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');
}
});
Expand Down

0 comments on commit 90efc18

Please sign in to comment.