[Added] Use custom options to create a select2 object
Posted: Sat Dec 18, 2021 6:58 pm
To create a select2 object with custom options, declare a function nuOnSetSelect2Options() in BE (PHP):
Note that the 2nd parameter of nuAddJavascript() is set to true to add the JS before the form/objects are created.
Here is a list of all the Select2 configuration options:
https://select2.org/configuration/options-api
Code: Select all
$s = "
function nuOnSetSelect2Options(i) {
return {
placeholder: 'This is my placeholder',
allowClear: true
};
}
";
nuAddJavascript($s, true);
Note that the 2nd parameter of nuAddJavascript() is set to true to add the JS before the form/objects are created.
Here is a list of all the Select2 configuration options:
https://select2.org/configuration/options-api