Skip to content

Commit

Permalink
Added a 500ms timeout to trigger server group validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Fofif committed May 15, 2013
1 parent e2171f6 commit 0eb1c83
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions installer/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ $(document).ready(function() {
this.element = $(fieldInGroup);
this.requiredGroups = new Array();
this.empty = true;
this.timer = null;

// Get required groups to validate this group
relatedGroups = this.element.attr('data-wity-require-groups');
Expand Down Expand Up @@ -494,7 +495,7 @@ $(document).ready(function() {

// A required group or a field within this group is not validated
// => cancel the checking with the server
if(abortAjax) {
if(abortAjax) {
if(!abortShowInvalidOnFields) {
this.showValid(false);
this.showValidOnFields(false);
Expand All @@ -508,7 +509,12 @@ $(document).ready(function() {
values.installer = WITY_INSTALLER.id;
values.step = this.step.name;

processAjax(document.location, values, this.processResponse, this);
// Added a timeout to give the time to user to input some non required fields
// which can change the result of the group validation on server side
// @todo Use normal method if group does not contain non required field
that.timer = setTimeout(function() {
processAjax(document.location, values, that.processResponse, that);
}, 500);
};

/**
Expand Down Expand Up @@ -672,6 +678,7 @@ $(document).ready(function() {

// Defines validate event "blur"
this.element.on('change blur', function() {that.validateInField();});
this.element.on('focus', function() {clearTimeout(that.group.timer);});
};

/**
Expand Down

0 comments on commit 0eb1c83

Please sign in to comment.