Permalink
Browse files

Add should-be-present behavior

  • Loading branch information...
kangax kangax
kangax authored and kangax committed May 16, 2008
1 parent 32f86d7 commit 11e4a910fa581142aad7f772aff5ff53e390340c
Showing with 20 additions and 4 deletions.
  1. +16 −0 behavior.should_be_present.js
  2. +4 −4 form.element.methods.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 });
+ }
+})
View
@@ -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) {
- return $(element).getElements().any(Element.present);
-};
+Field.Methods.isBlank = function(element) {
+ return $F(element).blank();
+}
/**
* Boosts Field#present to work somewhat more reasonably

0 comments on commit 11e4a91

Please sign in to comment.