Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add Validator::hasField()

This will be useful in form building as fields without validation sets
should not default to required.
  • Loading branch information...
commit 20b9b01b3c9ee3a2d3f605c32d605ef41833ead0 1 parent f36b167
@markstory markstory authored
View
10 src/Validation/Validator.php
@@ -113,6 +113,16 @@ public function field($name, ValidationSet $set = null) {
}
/**
+ * Check whether or not a validator contains any rules for the given field.
+ *
+ * @param string $name The field name to check.
+ * @return boolean
+ */
+ public function hasField($name) {
+ return isset($this->_fields[$name]);
+ }
+
+/**
* Associates an object to a name so it can be used as a provider. Providers are
* objects or class names that can contain methods used during validation of for
* deciding whether a validation rule can be applied. All validation methods,
View
3  tests/TestCase/Validation/ValidatorTest.php
@@ -50,9 +50,12 @@ public function testAddingRulesToField() {
*/
public function testFieldDefault() {
$validator = new Validator;
+ $this->assertFalse($validator->hasField('foo'));
+
$field = $validator->field('foo');
$this->assertInstanceOf('\Cake\Validation\ValidationSet', $field);
$this->assertCount(0, $field);
+ $this->assertTrue($validator->hasField('foo'));
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.