-
-
Notifications
You must be signed in to change notification settings - Fork 144
Closed
Labels
Description
After recent updates typing wasn't working in any of my select2 widgets that were inside bootstrap modals. Then I found this solution which seems to have worked for me: select2/select2#1436
It was working fine before I did the update on everything and now I don't know what the cause of the problem is (either update of select2 widget or yii2 update), but since that solution is from almost 2 years ago I have a feeling that the problem is somewhere in your widget, because it was updated very recently.
BychekRU
Metadata
Metadata
Assignees
Labels
Projects
Milestone
Relationships
Development
Select code repository
Activity
kartik-v commentedon Jun 3, 2015
You need to check the demos and docs pages for the widget.
The Select2 widget works perfectly with modal. You need to set the Modal markup correctly for it to work. Check the demo page and scroll down to button for example for Select2 inside a MODAL.
Note the important setting for the Modal dialog... the
tabindex
must NOT be set and must be set tofalse
as shown.embambols commentedon Jun 5, 2015
Ok. Thanks. It's just that it worked fine before, even without setting 'tabindex' => false. Have quite few places to update now :)
sankam-nikolya commentedon May 6, 2016
thx
elviskudo commentedon Jun 11, 2016
sorry for open this issue again,
now i found that problem again
cannot any typing on this widget in modal
and i see tab-index=-1
how can i solve this problem, thanks
alvarolordelo commentedon Apr 15, 2017
how to set it required like HTML 5 validation
field($model, 'end_cidade_id')->widget(\kartik\widgets\Select2::classname(), [ 'data' => \yii\helpers\ArrayHelper::map(\app\modulos\estoque\models\EndCidade::find()->where(['end_estado_id' => $model->end_estado_id])->orderBy('name')->asArray()->all(), 'id', 'name'), 'options' => [ 'required' => 'required', 'placeholder' => 'Selecione a cidade' ], 'pluginOptions' => [ 'allowClear' => true ], ]); ?>'required' => 'required' inside options isn't working
it should shown a required pop-up
kinandkwin commentedon May 9, 2017
Can't type anything if select2 in modal when using Firefox, Chrome works fine. Can you help me with this? thank you!
sebastian-velasquez commentedon Jul 19, 2017
https://stackoverflow.com/questions/18487056/select2-doesnt-work-when-embedded-in-a-bootstrap-modal
robov commentedon Aug 27, 2017
Although I have it working in a bootstap modal... it works in chrome... but not in firefox...
Any ideas ?
I was so flabbergasted by this that I did not see the previous post...
worked for me
dzona commentedon Oct 27, 2017
$.fn.modal.Constructor.prototype.enforceFocus = $.noop;
kartik-v commentedon Oct 27, 2017
You may want to set
dropdownParent
property of Select2 to the Modal Dialog identifier for addressing this (have not tested this though... for example):lieszkol commentedon May 29, 2018
Kartik's last example is the PROPER solution of the three, but it should really be:
(of course you should substitute modalDialogId with the actual ID of the modal dialog)
Summarizing it all:
The problem is Bootstrap Modal inserting some js that grabs the focus of anything not inside of the modal. The Select2 drop-down is actually rendered outside of the Modal DOM element. There are three ways to fix this:
This is also the "accepted" solution here:
Unfortunately, it is a hack and has some side-effects like breaking the ESC key to exit the modal, and scrolling issues if the modal is very long.
This is detailed also on the link above as well as here:
But again, this is a hack and has side-effects.
This is also described in the two links above and mentioned above by Kartik.
To implement the proper solution that doesn't break intended bootstrap modal functionality, do what is written at the top of this post!