Always use custom label in place of field name

Fixes: https://github.com/vlucas/valitron/issues/32
This commit is contained in:
Vance Lucas 2013-11-11 15:02:19 -06:00
parent 247f6f3112
commit d51f4c0fa5
2 changed files with 21 additions and 0 deletions

View File

@ -465,6 +465,10 @@ class Validator
if($param instanceof \DateTime) { if($param instanceof \DateTime) {
$param = $param->format('Y-m-d'); $param = $param->format('Y-m-d');
} }
// Use custom label instead of field name if set
if(isset($this->_labels[$param])) {
$param = $this->_labels[$param];
}
$values[] = $param; $values[] = $param;
} }

View File

@ -545,6 +545,23 @@ class ValidateTest extends BaseTestCase
), $v->errors()); ), $v->errors());
} }
public function testCustomLabelArrayWithoutMessage()
{
$v = new Valitron\Validator(array(
'password' => 'foo',
'passwordConfirm' => 'bar'
));
$v->rule('equals', 'password', 'passwordConfirm');
$v->labels(array(
'password' => 'Password',
'passwordConfirm' => 'Password Confirm'
));
$v->validate();
$this->assertEquals(array(
'password' => array("Password must be the same as 'Password Confirm'"),
), $v->errors());
}
/** /**
* Custom rules and callbacks * Custom rules and callbacks
*/ */