Page 1 of 1

[Added] Use custom options to create a select2 object

Posted: Sat Dec 18, 2021 6:58 pm
by admin
To create a select2 object with custom options, declare a function nuOnSetSelect2Options() in BE (PHP):

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