Skip to content

Commit

Permalink
Exposed custom error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mipotech authored Oct 20, 2020
1 parent 641eb00 commit 15f0974
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions IsraeliIdValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@
*/
class IsraeliIdValidator extends Validator
{
/**
* @var string custom error message for invalid checksum
*/
public $messageInvalidChecksum;
/**
* @var string custom error message for invalid characters
*/
public $messageInvalidChars;
/**
* @var string custom error message for number too long
*/
public $messageTooLong;
/**
* @var string custom error message for number too short
*/
public $messageTooShort;

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -111,10 +128,10 @@ public function clientValidateAttribute($model, $attribute, $view)
protected function getErrorMessages(): array
{
return [
'invalidChecksum' => Yii::t('tzvalidator', 'ID number is not valid'),
'invalidChars' => Yii::t('tzvalidator', 'ID number must include only digits'),
'tooLong' => Yii::t('tzvalidator', 'ID number must be no more than 9 digits'),
'tooShort' => Yii::t('tzvalidator', 'ID number must be at least 5 digits'),
'invalidChecksum' => $this->messageInvalidChecksum ?: Yii::t('tzvalidator', 'ID number is not valid'),
'invalidChars' => $this->messageInvalidChars ?: Yii::t('tzvalidator', 'ID number must include only digits'),
'tooLong' => $this->messageTooLong ?: Yii::t('tzvalidator', 'ID number must be no more than 9 digits'),
'tooShort' => $this->messageTooShort ?: Yii::t('tzvalidator', 'ID number must be at least 5 digits'),
];
}
}

0 comments on commit 15f0974

Please sign in to comment.