From 3a98342ec7d53e54c6d4c3abb912a3b2b9ba4a48 Mon Sep 17 00:00:00 2001 From: jlukic Date: Tue, 12 May 2015 16:24:14 -0400 Subject: [PATCH] Form Validation: fix reset/clear triggering validation on checkbox. Fix form validation requiring checkbox js --- src/definitions/behaviors/form.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/definitions/behaviors/form.js b/src/definitions/behaviors/form.js index 1ee1ff776..e944dcc60 100644 --- a/src/definitions/behaviors/form.js +++ b/src/definitions/behaviors/form.js @@ -177,7 +177,7 @@ $.fn.form = function(parameters) { $element.dropdown('clear'); } else if(isCheckbox) { - $element.checkbox('uncheck'); + $field.prop('checked', false); } else { module.verbose('Resetting field value', $field, defaultValue); @@ -195,11 +195,14 @@ $.fn.form = function(parameters) { $element = $field.parent(), $fieldGroup = $field.closest($group), $prompt = $fieldGroup.find(selector.prompt), - defaultValue = $field.data(metadata.defaultValue) || '', + defaultValue = $field.data(metadata.defaultValue), isCheckbox = $element.is(selector.uiCheckbox), isDropdown = $element.is(selector.uiDropdown), isErrored = $fieldGroup.hasClass(className.error) ; + if(defaultValue === undefined) { + defaultValue = ''; + } if(isErrored) { module.verbose('Resetting error on field', $fieldGroup); $fieldGroup.removeClass(className.error); @@ -211,12 +214,7 @@ $.fn.form = function(parameters) { } else if(isCheckbox) { module.verbose('Resetting checkbox value', $element, defaultValue); - if(defaultValue === true) { - $element.checkbox('check'); - } - else { - $element.checkbox('uncheck'); - } + $field.prop('checked', defaultValue); } else { module.verbose('Resetting field value', $field, defaultValue); @@ -589,6 +587,9 @@ $.fn.form = function(parameters) { : $field.val() ; $field.data(metadata.defaultValue, value); + if(isCheckbox) { + console.log($field.is(':checked'), $field, $field.data(metadata.defaultValue)); + } }) ; },