search field Select2 seems not to work with Bootstrap5
search field Select2 seems not to work with Bootstrap5
var editor = new $.fn.dataTable.Editor( {
ajax: 'php/table.partijen.php',
table: '#partijen',
fields: [
{
"label": "rv:",
"name": "partijen.rv",
type: "select2"
},
{
"label": "titel:",
"name": "partijen.titel"
},
{
"label": "familienaam:",
"name": "partijen.familienaam"
},
{
"label": "vertegenwoordiger:",
"name": "partijen.vertegenwoordiger"
},
{
"label": "volet:",
"name": "partijen.volet"
},
{
"label": "vovoe:",
"name": "partijen.vovoe"
}
]
} );
Since I use Bootstrap5 I am not able to use the search field in Select2
What am I doing wrong here?
Thanks.
This question has an accepted answers - jump to answer
Answers
To initialise bootstrap5 and select2 I have used:
To initialise bootstrap5 and select2 I have used:
It never worked.
Select2 works in a standard Bootstrap modal following this guide: https://select2.org/troubleshooting/common-problems
But it doesn't work in an Editor modal.
It seems a Css problem, but I never figured out how to fix it.
The select2 input seems to work with Editor in your example. I'm able to select and change the options. However the table displays the value not the label. This thread might help to display the label in the table.
Please provide the steps to recreate the problem in your test case.
Kevin
You're able to select and change the options, but if you click on the search field the focus goes to the close X button on the top right.
The actual workaround is to disable search field or switch to a different library, like Selectize or Choice.
May be you can use
open
oropened
to execute this code:Kevin
@carlop : Select2 worked perfectly under Bootstrap4, thanks for the suggestion I will switch to Selectize for Bootstrap5, that works as wanted.
Thanks all!
Jan
I had the exact same issue and spent hours trying to fix. I was finally able to fix using @kthorngren suggestion (field would need to be explicitly given an id)
The only downside of using this direct method is that I had to do it for each filed that used select2. So I found a workaround on the plugin website and customized it further to make it work on all select2 instances