Skip to content

Commit

Permalink
Allow to check if the form is valid programatically and fixing that u…
Browse files Browse the repository at this point in the history
…nchecked listeners were marking the form as with errors when there was no error
  • Loading branch information
Eduardo Robles Elvira committed May 29, 2013
1 parent bf364cf commit 4707988
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
7 changes: 7 additions & 0 deletions nod.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ Nod = (function() {
if (!fields) {
return;
}
this.form[0].__nod = this;
this.get = jQuery.extend({
'delay': 700,
'disableSubmitBtn': true,
Expand Down Expand Up @@ -376,6 +377,9 @@ Nod = (function() {

Nod.prototype.formIsErrorFree = function() {
return !jQuery(this.listeners).filter(function() {
if (this.status === null) {
this.runCheck();
}
return !this.status;
}).length;
};
Expand Down Expand Up @@ -410,6 +414,9 @@ Nod = (function() {


$.fn.nod = function(fields, settings) {
if (fields === void 0 && settings === void 0) {
return this[0].__nod;
}
new Nod(this, fields, settings);
return this;
};
Expand Down
4 changes: 2 additions & 2 deletions nod.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions nod/init.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
$.fn.nod = ( fields, settings ) ->
if fields == undefined && settings == undefined
return this[0].__nod
new Nod( this, fields, settings )
return this
8 changes: 7 additions & 1 deletion nod/nod.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class Nod
# Silent fail if no fields where passed in.
unless fields then return

@form[0].__nod = this

# Defining variables used throughout the plugin.
@get = jQuery.extend
'delay' : 700 # Keyup > delay(ms) > input check
Expand Down Expand Up @@ -146,7 +148,11 @@ class Nod

# Helper to check if the form is free of errors. Returns a boolean.
formIsErrorFree : =>
!jQuery( @listeners ).filter( -> !@status ).length
!jQuery( @listeners ).filter( ->
if this.status == null
this.runCheck()
return !@status
).length


# Helper fn used in the constructor to see if both the form and the submit
Expand Down

0 comments on commit 4707988

Please sign in to comment.