2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-14 19:15:41 +00:00

Logic fix for boolean fields in JS forms

This commit is contained in:
Oliver
2021-11-22 21:46:45 +11:00
parent 8030ca0bb9
commit 10dec7743e

View File

@ -804,7 +804,9 @@ function updateFieldValue(name, value, field, options) {
switch (field.type) { switch (field.type) {
case 'boolean': case 'boolean':
el.prop('checked', value); if (value == true || value.toString().toLowerCase() == 'true') {
el.prop('checked');
}
break; break;
case 'related field': case 'related field':
// Clear? // Clear?
@ -2019,8 +2021,15 @@ function constructInputOptions(name, classes, type, parameters) {
} }
if (parameters.value != null) { if (parameters.value != null) {
if (parameters.type == 'boolean') {
// Special consideration of a boolean (checkbox) value
if (parameters.value == true || parameters.value.toString().toLowerCase() == 'true') {
opts.push('checked');
}
} else {
// Existing value? // Existing value?
opts.push(`value='${parameters.value}'`); opts.push(`value='${parameters.value}'`);
}
} else if (parameters.default != null) { } else if (parameters.default != null) {
// Otherwise, a defualt value? // Otherwise, a defualt value?
opts.push(`value='${parameters.default}'`); opts.push(`value='${parameters.default}'`);