Skip to content

Commit f55c2cd

Browse files
authored
feat(checkbox): detect on as checked and add checkbox string values
Using set values for a checkbox field inside a form will only accept "true" or "1" to recognize the field as checked. However, the standard value for a checked checkbox (when retrieved by "get values") is "on". This PR now accepts a possible "on" value for given checkbox fields to also check the checkbox to have the same bahavior. In addition, any string value will now be set as value for the checkbox as well. (This is valid specification as of developer.mozilla.org/en-US/docs/Web/HTML/Element/Input/checkbox#value), but any other string than "on" will not check the checkbox.
1 parent 3edbfe3 commit f55c2cd

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/definitions/behaviors/form.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,12 +1086,15 @@ $.fn.form = function(parameters) {
10861086
}
10871087
else if(isCheckbox) {
10881088
module.verbose('Setting checkbox value', value, $element);
1089-
if(value === true || value === 1) {
1089+
if(value === true || value === 1 || value === 'on') {
10901090
$element.checkbox('check');
10911091
}
10921092
else {
10931093
$element.checkbox('uncheck');
10941094
}
1095+
if(typeof value === 'string') {
1096+
$field.val(value);
1097+
}
10951098
}
10961099
else if(isDropdown) {
10971100
module.verbose('Setting dropdown value', value, $element);

0 commit comments

Comments
 (0)