Issue
I have 2 fields in a form pricemark and price, when user select pricemark value = other
user can not enter a value less than 250. I need a validation rule for it in yii2
but its not working . here is my code
['price', 'min' => 250, 'when' => function ($model) {
return $model->priceMark == 'other';
}],
Solution
Try this:
['price', 'number', 'min' => 250, 'when' => function ($model) {
return $model->priceMark == 'other';
}, 'whenClient' => 'function (attribute, value) {
return $("<field>").val() == "other";
}'],
where <field>
is the priceMark
element identifier like its class or ID (i.e. #price_pricemark
if model name is Price
).
Answered By - Bizley
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.