Skip to content

Cannot validate a MultiSelect field #6250

Closed Answered by dominik-eller
dominik-eller asked this question in Q&A
Discussion options

You must be logged in to vote

Ok I found a solution that works for me

->rules('required', 'json', function($attribute, $value, $fail) {
            $options = ['Option A', 'Option B', 'Option C'];
            $valueArray = json_decode($value);
            $containsOption = array_intersect($options, $valueArray);
            if(empty($containsOption)) {
                $fail('The selected reason should contain at least one allowed option.');
            }
        })

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@dominik-eller
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by dominik-eller
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #6248 on March 04, 2024 00:57.