Reputation: 16181
I'm using ActiveForm to generate my form. In the model, I have the following rules for the same field:
public function rules() {
return [
['reviewMsg', 'required', 'message' => Yii::t('review', 'Review message cannot be blank.')],
['reviewMsg', 'string', 'max' => 255, 'message' => Yii::t('review', 'Review message should contain at most 255 characters.')],
];
}
Now, client-side validation works fine, it reacts to the rules correctly. The custom message for breaking the required
rule is shown as I specified it. However, the second custom message (text <= 255 characters) is being ignored, and instead a standard error message is shown.
What am I doing wrong?
Upvotes: 1
Views: 350
Reputation: 9358
Use tooLong property:
public function rules() {
return [
['reviewMsg', 'required', 'message' => Yii::t('review', 'Review message cannot be blank.')],
['reviewMsg', 'string', 'max' => 255, 'tooLong' => Yii::t('review', 'Review message should contain at most 255 characters.')],
];
}
Upvotes: 3