Laravel: select2 in single page not work
I am using this code.
"use strict";// Class definition
let KTSearch = function () {
// Private variables
let form;
// Init Select2
const initSelectXYZ = () => {
// Init Select2 --- more info: https://select2.org/
$('[name="provincia_id"]').select2();
}
// Public methods
return {
init: function () {
form = document.getElementById('kt_search_form');
initSelectXYZ();
}
};
}();
// On document ready
KTUtil.onDOMContentLoaded(function () {
KTSearch.init();
});
When I try to run the code, it tells me it can't find select2:
Uncaught TypeError: $(...).select2 is not a function
But if I use data-control="select2" in html code, it works. why?
Replies (2)
Try adding the select2 script to your application.
Hi,
Sorry for the delay, and we miss looked into this issue. Could you please try to add the below code on top of this file?
require('select2');
Thanks