-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Values array validation (from multiple select) #3376
Comments
It wiil be very usefull to have universal validator, which we can use with any other validator. Not only range. For example:
or
Search forms with multiple selects or checkbox groups are very common, imo. |
Which validators need array support? |
In my case: range and integer. Also it will be usefull for filter. |
it good idea for multiselect :) [['status_id'], 'each', 'in', 'range' => array_keys(static::getStatusLabels())] |
Imo. This is common scenario, i also encounter this scenario on Yii1 for 3-4projects. Would be good if this is on the core. 👍 for this. |
I have the same problem described, which was the best found solution, since I have searched and read and I can not find solution to the issue, I opened the question in the forum and facebook and no answer, I would like to be able to establish this enhancement. Solved use extension https://github.com/mickgeek/yii2-actionbar for filter multiple gridview via ajax. |
i solve via ['name', 'exist', 'allowArray' => true, 'when' => function ($model, $attribute) {return is_array($model->$attribute);}], and in Notice: need do implode by comma to string before render value into input filter |
thank you very much for the reply, I commented that the extension because besides making a multiple filter in the gridview, I can also filter the checkboxcolumn to delete selected records, download selected records. Solution provided by: @mickgeek I hope it will serve as a guide to someone. |
Resolved by #8023 |
@klimov-paul, thanks! |
👍 |
You are welcome. |
I have model Order with attribute status_id. This attribute must have only one of this values: [1, 2, 3]. I want to make search model and form with multiple select tag, which correspond to status_id attribute. What validation rule can I use for status_id to allow multiple values (to call Order::find()->andFilterWhere(['in', 'status_id', $this->status_id]) in search model) and validate each of them against an array [1, 2, 3]?
I think this is common usecase, so if Yii doesn't have an out-of-box solution for this, it needs an enhancement.
The text was updated successfully, but these errors were encountered: