Answer the question
In order to leave comments, you need to log in
How to properly set up clientValidation in Yii 1.1.14?
Guys, please explain. I want to validate the form on the client side (and when validating, only add the .error class to the clumsy input without displaying error messages, so I don’t add $form->errorSummary, etc. to the view). Judging by the documentation, I realized that it is necessary to pass TRUE to the enableClientValidation parameter like this:
$checkOrderForm = $this->beginWidget('CActiveForm', array(
'id' => 'check-order-form',
'stateful' => true,
'enableClientValidation' => TRUE,
));
rules() {
return array(
// типы полей
array('id, order_start_time, order_finish_time, order_status_id, boiler_id, price_boiler, price_delivery', 'numerical', 'integerOnly' => true),
array('name, email, address_delivery', 'length', 'max' => 255),
array('name', 'length', 'min' => 2),
array('phone', 'length', 'max' => 25),
array('phone', 'length', 'min' => 5),
array('email', 'email'),
// сценарий оставления заявки
array('name, phone, email, boiler_id', 'required', 'on' => 'add'),
// сценарий подтверждения заявки (через админку)
array('name, phone, email, address_delivery, order_status_id, boiler_id, price_boiler, price_delivery', 'required', 'on' => 'confirm'),
// сценарий проверки статуса заявки
array('id', 'required', 'on' => 'check'),
}
Answer the question
In order to leave comments, you need to log in
In order for client-side validation to work, the form must have calls to CActiveForm::error() for all fields that require validation, regardless of whether errors should be displayed visually or not. In the latter case, you also need to add the corresponding parameter:
$checkOrderForm = $this->beginWidget('CActiveForm', array(
'id' => 'check-order-form',
'stateful' => true,
'enableClientValidation' => TRUE,
'clientOptions' => array(
'hideErrorMessage' => true,
),
));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question