M
M
Maxim Timofeev2015-07-11 19:49:57
Yii
Maxim Timofeev, 2015-07-11 19:49:57

How to write rules in a dependency model?

There is a form in it there are fields which are added by means of jquery. There are a number of fields that should only be required if these fields are added.
For example, the "add product" button adds some input with the product id, there can be many of
them. If there is at least one such input, then the fields "delivery address" and "recipient name" are added.
How to write rules in the model for the fields "delivery address" " and "recipient name' so that they are only required if there is at least one product?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2015-07-11
@webinar

Here I found 'whenClient' :

public function rules()
    {
        return [
          //...
           [
                ['kol'], 'integer', 'min' => 1, 'when' => function ($model) { return !empty($model->tov_id); },
                'whenClient' => "function (attribute, value) { return $('#ordtov-0-tov_id').val() != 0;}" //javascript условие проверки
            ],
          //...
        ];
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question