diff --git a/ampersand-checkbox-view.js b/ampersand-checkbox-view.js index 3655246..f7f1fb7 100644 --- a/ampersand-checkbox-view.js +++ b/ampersand-checkbox-view.js @@ -26,7 +26,6 @@ module.exports = View.extend({ this.value = this.startingValue; this.label = opts.label || opts.name; this.required = (typeof opts.required === 'boolean') ? opts.required : false; - this.disabled = (typeof opts.disabled === 'boolean') ? opts.disabled : false; this.validClass = opts.validClass || 'input-valid'; this.invalidClass = opts.invalidClass || 'input-invalid'; this.requiredMessage = opts.requiredMessage || 'This box must be checked.'; @@ -37,6 +36,22 @@ module.exports = View.extend({ this.setValue(this.value); }, + + props: { + disabled: { + type: 'boolean', + default: false + } + }, + + bindings: { + disabled: { + type: 'booleanAttribute', + selector: 'input', + name: 'disabled' + } + }, + clear: function () { return this.setValue(false); }, @@ -62,7 +77,6 @@ module.exports = View.extend({ this.setMessage(this.message); this.input.checked = !!this.value; - this.input.disabled = this.disabled; this.input.name = this.name; this.labelEl.textContent = this.label; }, diff --git a/test/index.js b/test/index.js index f0d6650..85e2e8c 100644 --- a/test/index.js +++ b/test/index.js @@ -104,6 +104,11 @@ test('basics', function (t) { t.strictEqual(view.disabled, true, 'disabled should be true'); t.strictEqual(view.input.disabled, true, 'disabled should be true'); + view.disabled = false; + + t.strictEqual(view.disabled, false, 'disabled should now be false'); + t.strictEqual(view.input.disabled, false, 'disabled should now be false'); + //test throw when lacking name t.throws(function() { view = new CheckboxView({