Answer the question
In order to leave comments, you need to log in
Is it possible to add client validation when creating custom validation rule in Yii?
Hello,
Is it possible to create a client-side validation rule for a field while creating a custom validation method in the model?
For example:
array('agentReward', 'checkRewardValidation', 'on' => self::SCENARIO_FRONT_CREATE)
public function checkRewardValidation($attribute, $params = array()) {
/* Здесь какой либо код который добавляет валидацию поля agentReward на клиенте */
}
Answer the question
In order to leave comments, you need to log in
For those who are faced with this problem, and do not want to waste time looking for a solution, it is done like this:
array('agentReward', 'checkRewardValidation', 'clientValidate' => 'clientCheckRewardValidation', 'on' => self::SCENARIO_FRONT_CREATE),
public function clientCheckRewardValidation($attribute, $params = array()) {
if (!isset($params['message']))
$params['message'] = 'Value should be 123';
$js = "if(value != '123') { messages.push('".$params['message']."'); }";
return $js;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question