PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, February 18, 2022

[FIXED] Yii2 conditional validation rule on basis of minimum value

 February 18, 2022     php, validation, yii, yii2     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing