Skip to content
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

maximumSelectionLength with tokenSeparator in multi-select #322

Closed
buttflattery opened this issue Jun 3, 2020 · 1 comment
Closed

maximumSelectionLength with tokenSeparator in multi-select #322

buttflattery opened this issue Jun 3, 2020 · 1 comment
Labels

Comments

@buttflattery
Copy link

buttflattery commented Jun 3, 2020

The issue mentioned here select2/select2#3514 isnt working in select2

echo $form->field(
            $model,
            'keyword',
            [
                'template' => '{input}{error}',
            ]
        )->widget(
            Select2::class,
            [
                'data' => empty($model->keyword) ? [''] : '',
                'options' => [
                    'placeholder' => 'keyword',
                    'class' => 'form-control',
                    'multiple' => true,
                ],
                'showToggleAll' => false,
                'theme' => Select2::THEME_BOOTSTRAP,
                
                'pluginOptions' => [
                    'tags' => true,
                    'maximumSelectionLength'=>5,
                    'allowClear' => false,
                    'tokenSeparators' => [',', ' '],
                    'closeOnSelect'=>false,
                ],
               
            ]
        )->label(false);

The above still allows you to select more than 5 if we use the tokenSeparator option.

image

unless i use select2:selecting and return false from it like below

 'pluginEvents'=>[
                    'select2:selecting'=>'function(){
                                                if (
                            $(this).select2("data").length >=$(this).data("select2").results.data.maximumSelectionLength
                          ) {
                            $(this).select2("close");
                          }
                    }'
                ]

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@stale
Copy link

stale bot commented Aug 5, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Aug 5, 2020
@stale stale bot closed this as completed Aug 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant