Answer the question
In order to leave comments, you need to log in
[[+content_image]]
How to remove the required field?
public function rules()
{
return [
[['car_id', 'driver_id'], 'required'],
[['car_id', 'driver_id', 'use_new_tariffs', 'town', 'town_center', 'km_price'], 'integer'],
[['car_id'], 'exist', 'skipOnError' => true, 'targetClass' => Car::className(), 'targetAttribute' => ['car_id' => 'id']],
[['driver_id'], 'exist', 'skipOnError' => true, 'targetClass' => Driver::className(), 'targetAttribute' => ['driver_id' => 'id']],
[['town', 'town_center', 'km_price'], 'required', 'when' => function($model){
return $model->use_new_tariffs;
}],
];
}
Answer the question
In order to leave comments, you need to log in
Use conditional validation.
through WhenClient hang on your checkbox or input, well, or whatever you have.
You have it implemented, but the model is stuck, try using the variable from your checkbox as in the example at the link. like this.$model->checkBox == true;
As an option:
You can use ajax validation and do this check in the validation action. For example, you can make different scenarios for the model.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question