Skip to content
This repository has been archived by the owner on Nov 10, 2018. It is now read-only.

Commit

Permalink
disabling validation during modifier key presses so you can apple+a o…
Browse files Browse the repository at this point in the history
…n an input without it goin' crazy on it.
  • Loading branch information
3n committed Feb 24, 2011
1 parent a67aedb commit 6ecbd60
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -104,6 +104,7 @@ ValidateSimple Method: constructor
* validateEvent - (string: defaults to 'keyup') event name for input validation.
* initialValidation - (boolean: defaults to true) validate all inputs on instantiation.
* alertUnedited - (boolean: defaults to true) alert inputs that have not been edited.
* noValidateKeys - (array) array of key codes (event.key) that will disable validation during keypress.
* checkPeriodical - (number: defaults to 1000) how often to check for changed inputs. This comes
in handy when the user uses and automated form filler like 1Password, which does not fire any
events.
Expand Down
14 changes: 13 additions & 1 deletion Source/ValidateSimple.js
Expand Up @@ -69,7 +69,17 @@ var ValidateSimple = new Class({

attach: function(){
if (!this.active){
this.active = true;
this.active = true;

$(document.body).addEvent('keydown', function(e){
if (this.options.noValidateKeys.contains(e.key))
this.active = false;
}.bind(this));
$(document.body).addEvent('keyup', function(e){
if (this.options.noValidateKeys.contains(e.key))
(function(){ this.active = true; }).delay(100, this);
}.bind(this));

this.inputs.each(function(input){
input.addEvent(this.options.validateEvent, function(e){
if (e.key !== 'tab') input.store('validate-simple-touched', true);
Expand Down Expand Up @@ -128,6 +138,7 @@ var ValidateSimple = new Class({
deactivate: function(){ this.detach(); },

validateInput: function(input){
if (!this.active) return this;
var validatorTypes = input.get(this.options.attributeForType),
validators = [];

Expand Down Expand Up @@ -173,6 +184,7 @@ var ValidateSimple = new Class({
},

alertInputValidity: function(input){
if (!this.active) return this;
var inputValid = input.retrieve('validate-simple-is-valid'),
isEdited = this.options.alertUnedited ? true : input.retrieve('validate-simple-touched');

Expand Down

0 comments on commit 6ecbd60

Please sign in to comment.