ampersand-checkbox-view
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -18,7 +18,7 @@ var domify = require('domify'); | ||
function CheckboxView(opts) { | ||
if (!opts.name) throw new Error('must pass in a name'); | ||
if (!opts || !opts.name) throw new Error('must pass in a name'); | ||
// settings | ||
this.name = opts.name; | ||
this.value = opts.value || ''; | ||
this.value = (opts.value === true) || false; | ||
this.el = opts.el; | ||
@@ -44,7 +44,3 @@ this.template = opts.template || template; | ||
if (this.isValid()) { | ||
this.hasBeenValid = true; | ||
} | ||
// always start true with checkboxes | ||
this.valid = true; | ||
this.test(); | ||
} | ||
@@ -72,4 +68,4 @@ | ||
this.setMessage(this.message); | ||
if (this.required) this.input.required = true; | ||
this.input.value = !!this.value; | ||
this.input.checked = !!this.value; | ||
this.input.name = this.name; | ||
this.labelEl.textContent = this.label; | ||
@@ -84,5 +80,3 @@ this.rendered = true; | ||
this.value = this.input.checked; | ||
if (this.message || this.hasBeenValid) { | ||
this.valid = this.runTests(); | ||
} | ||
this.test(); | ||
if (this.parent) this.parent.update(this); | ||
@@ -97,3 +91,3 @@ }; | ||
// there is an error | ||
if (message && this.hasBeenValid) { | ||
if (message && this.shouldValidate) { | ||
this.messageContainer.style.display = 'block'; | ||
@@ -105,3 +99,3 @@ this.messageEl.textContent = message; | ||
this.messageContainer.style.display = 'none'; | ||
if (this.hasBeenValid && this.editedDirectly) { | ||
if (this.shouldValidate && this.editedDirectly) { | ||
dom.addClass(input, this.validClass); | ||
@@ -119,18 +113,15 @@ dom.removeClass(input, this.invalidClass); | ||
CheckboxView.prototype.beforeSubmit = function () { | ||
this.hasBeenValid = true; | ||
this.valid = this.runTests(); | ||
this.shouldValidate = true; | ||
this.handleInputEvent(); | ||
}; | ||
CheckboxView.prototype.isValid = function () { | ||
return !!(!this.required || this.input.checked); | ||
}; | ||
// runs tests and sets first failure as message | ||
CheckboxView.prototype.runTests = function () { | ||
var valid = this.isValid(); | ||
if (valid) { | ||
this.hasBeenValid = true; | ||
CheckboxView.prototype.test = function () { | ||
var valid = !this.required || this.value; | ||
if (valid) this.shouldValidate = true; | ||
this.valid = valid; | ||
if (this.shouldValidate && !valid) { | ||
this.setMessage(this.requiredMessage); | ||
} else { | ||
this.setMessage(''); | ||
} | ||
this.setMessage(valid ? '' : this.requiredMessage); | ||
return valid; | ||
@@ -137,0 +128,0 @@ }; |
{ | ||
"name": "ampersand-checkbox-view", | ||
"description": "A view module for intelligently rendering and validating checkbox input. Works well with ampersand-form-view.", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"author": "Henrik Joreteg <henrik@andyet.net>", | ||
@@ -10,5 +10,16 @@ "bugs": { | ||
"dependencies": { | ||
"ampersand-dom": "~0.1.1", | ||
"ampersand-dom": "^0.1.2", | ||
"domify": "~1.2.2" | ||
}, | ||
"devDependencies": { | ||
"ampersand-view-conventions": "^1.1.1", | ||
"browserify": "~4.1.10", | ||
"function-bind": "~0.1.0", | ||
"jshint": "~2.5.1", | ||
"precommit-hook": "~1.0.2", | ||
"run-browser": "~1.3.1", | ||
"tap-spec": "~0.2.0", | ||
"tape": "~2.13.3", | ||
"tape-run": "~0.1.1" | ||
}, | ||
"homepage": "https://github.com/ampersandjs/ampersand-checkbox-view", | ||
@@ -26,6 +37,22 @@ "keywords": [ | ||
}, | ||
"devDependencies": { | ||
"jshint": "~2.5.1", | ||
"precommit-hook": "~1.0.2" | ||
"scripts": { | ||
"test": "browserify test/* | tape-run | tap-spec", | ||
"start": "run-browser test/*" | ||
}, | ||
"testling": { | ||
"files": "test/*.js", | ||
"browsers": [ | ||
"ie/9..latest", | ||
"firefox/17..latest", | ||
"firefox/nightly", | ||
"chrome/22..latest", | ||
"chrome/canary", | ||
"opera/12..latest", | ||
"opera/next", | ||
"safari/5.1..latest", | ||
"ipad/6.0..latest", | ||
"iphone/6.0..latest", | ||
"android-browser/4.2..latest" | ||
] | ||
} | ||
} |
@@ -64,2 +64,6 @@ # ampersand-checkbox-view | ||
## browser support | ||
[![testling badge](https://ci.testling.com/AmpersandJS/ampersand-checkbox-view.png)](https://ci.testling.com/AmpersandJS/ampersand-checkbox-view) | ||
## credits | ||
@@ -66,0 +70,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10092
7
145
76
9
Updatedampersand-dom@^0.1.2