Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Update jquery.validate.js #467

Closed
wants to merge 1 commit into from

7 participants

@rattana

Added delay for remote

@rattana

remote function is activated each time we press a key in input fields.
So it sends an ajax request for each typed key, it's not very accuracy.
I propose a delay time before sending a remote request.

@dbcdeathdreamer

Rattana is right. I also look for decision for this problem .

@g1smd

Please correct the code and commit again.

The new commit will automatcally appear on the end of this pull request. :)

@Ciaro

this.submited => this.submitted

@jzaefferer
Owner

This PR has too many issues. Though I'll keep #466 open to keep track of the underlying issues.

@jzaefferer jzaefferer closed this
@bertoost

Hmm cannot see the isses.. Works fine for me!
Can you describe the issues you have?

@staabm
Collaborator

@bertoost this issue is a few years old and likely be fixed in the meantime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 25, 2012
  1. @rattana

    Update jquery.validate.js

    rattana authored
    Added delay for remote
This page is out of date. Refresh to see the latest.
Showing with 24 additions and 3 deletions.
  1. +24 −3 jquery.validate.js
View
27 jquery.validate.js
@@ -202,6 +202,14 @@ $.validator.format = function(source, params) {
return source;
};
+$.validator.delay = (function(){
+ var timer = 0;
+ return function(callback, ms){
+ clearTimeout (timer);
+ timer = setTimeout(callback, ms);
+ };
+})();
+
$.extend($.validator, {
defaults: {
@@ -217,6 +225,7 @@ $.extend($.validator, {
onsubmit: true,
ignore: ":hidden",
ignoreTitle: false,
+ keypressDelay: 350,
onfocusin: function(element, event) {
this.lastActive = element;
@@ -236,9 +245,21 @@ $.extend($.validator, {
onkeyup: function(element, event) {
if ( event.which == 9 && this.elementValue(element) === '' ) {
return;
- } else if ( element.name in this.submitted || element === this.lastActive ) {
- this.element(element);
- }
+ if("remote" in $(element).rules()) {
+ var submitted = this.submitted;
+ var lastActive = this.lastActive;
+ var validator = this;
+
+ $.validator.delay(function() {
+ if ( element.name in submitted || element == lastActive ) {
+ validator.element(element);
+ }
+ }, this.settings.keypressDelay);
+ } else {
+ if(element.name in this.submited ||element == this.lastActive) {
+ this.element(element);
+ }
+ }
},
onclick: function(element, event) {
// click on selects, radiobuttons and checkboxes
Something went wrong with that request. Please try again.