diff --git a/src/trait_manager/view/TraitCheckboxView.js b/src/trait_manager/view/TraitCheckboxView.js index fd706b1b3..c11c6da6b 100644 --- a/src/trait_manager/view/TraitCheckboxView.js +++ b/src/trait_manager/view/TraitCheckboxView.js @@ -1,3 +1,4 @@ +import { isUndefined } from 'underscore'; var TraitView = require('./TraitView'); module.exports = TraitView.extend({ @@ -16,7 +17,23 @@ module.exports = TraitView.extend({ * @private */ onChange() { - this.model.set('value', this.getInputEl().checked); + const value = this.getInputEl().checked; + this.model.set('value', this.getCheckedValue(value)); + }, + + getCheckedValue(checked) { + let result = checked; + const { valueTrue, valueFalse } = this.model.attributes; + + if (result && !isUndefined(valueTrue)) { + result = valueTrue; + } + + if (!result && !isUndefined(valueFalse)) { + result = valueFalse; + } + + return result; }, /** @@ -29,15 +46,21 @@ module.exports = TraitView.extend({ const el = TraitView.prototype.getInputEl.apply(this, args); if (toInit) { - let checked; + let checked, targetValue; const { model, target } = this; + const { valueTrue, valueFalse } = model.attributes; const name = model.get('name'); if (model.get('changeProp')) { checked = target.get(name); + targetValue = checked; } else { - checked = target.get('attributes')[name]; - checked = checked || checked === '' ? !0 : !1; + targetValue = target.get('attributes')[name]; + checked = targetValue || targetValue === '' ? !0 : !1; + } + + if (!isUndefined(valueFalse) && targetValue === valueFalse) { + checked = !1; } el.checked = checked;