Skip to content

Commit

Permalink
Add should-be-present behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
kangax authored and kangax committed May 16, 2008
1 parent 32f86d7 commit 11e4a91
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
16 changes: 16 additions & 0 deletions behavior.should_be_present.js
@@ -0,0 +1,16 @@
/**
* Fires "validation:failed" on a document,
* when any form that has "blank" fields
* with class "should-be-present" is submitted
*
* Passes "failed" elements as "elements" property on event's memo
*
**/
document.observe('submit', function(e) {
var required = e.target.select('.should-be-present')
.findAll(function(el) { return $F(el).blank() })
if (required.length) {
e.stop();
document.fire('validation:failed', { elements: required });
}
})
8 changes: 4 additions & 4 deletions form.element.methods.js
@@ -1,10 +1,10 @@
/** /**
* Are any of the form fields empty? * Returns true when element's value is "blank" (consists of 0 or more whitespaces)
* *
*/ */
Field.Methods.isEmpty = function(element) { Field.Methods.isBlank = function(element) {
return $(element).getElements().any(Element.present); return $F(element).blank();
}; }


/** /**
* Boosts Field#present to work somewhat more reasonably * Boosts Field#present to work somewhat more reasonably
Expand Down

0 comments on commit 11e4a91

Please sign in to comment.