Skip to content

Commit

Permalink
Impelement disabled via props and bindings; add tests
Browse files Browse the repository at this point in the history
Improves on #18/#20
Fixes #13
Fixe #14
  • Loading branch information
dhritzkiv committed May 27, 2017
1 parent 540fb35 commit d3ab49e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
18 changes: 16 additions & 2 deletions ampersand-checkbox-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
Expand All @@ -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);
},
Expand All @@ -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;
},
Expand Down
5 changes: 5 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit d3ab49e

Please sign in to comment.