Skip to content
Browse files

Added an additional method for determining if a field is in a valid s…

…tate
  • Loading branch information...
1 parent d3b0f8a commit 2ee3deef6e09b6121e7e0c30db58be73c324a222 @rikh42 committed Feb 14, 2013
Showing with 24 additions and 0 deletions.
  1. +24 −0 form/type/AbstractType.php
View
24 form/type/AbstractType.php
@@ -474,6 +474,30 @@ public function isValid()
return $valid;
}
+
+ /**
+ * Similar to isValid(), only it does not add any errors to the field.
+ * It is intended as a way of determining if the current state of the field
+ * is valid or not, and nothing else.
+ * @return bool
+ */
+ public function isInValidState()
+ {
+ // iterate over the validators on the field
+ foreach ($this->validators as $validator)
+ {
+ // if any are not valid, make a note of it
+ // we hope that the validators will set an appropriate error
+ // on us, so that it can be rendered in the view.
+ if (!$validator->isValid($this->get('value'))) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+
/**
* Adds an error message to the field
* This is normally called by one of the validators

0 comments on commit 2ee3dee

Please sign in to comment.
Something went wrong with that request. Please try again.