Hi,
It seems I'm unable to add items to the Select2 select object list, just select them.
I believe this funtionality is known as 'tagging', is it not available in nuBuilder?
Cheers,
Alan
Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
Search2 Select Object
-
- nuBuilder Team
- Posts: 4292
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 444 times
- Contact:
Re: Search2 Select Object
Hi Alan,
I found this on the official select2 documentation page:
https://select2.org/programmatic-contro ... lear-items
I found this on the official select2 documentation page:
https://select2.org/programmatic-contro ... lear-items
-
- Posts: 19
- Joined: Fri Mar 22, 2024 4:59 pm
Re: Search2 Select Object
Hi Kevin,
Yes, I've tried that but could not get it to work, the object just disappeared in nuBuilder.
I'm wondering whether you can actually just use the nuBuilder object names or some other extra syntax is required.
I couldn't really find which naminig convention to use from the F12 developer option.
Yes, I've tried that but could not get it to work, the object just disappeared in nuBuilder.
I'm wondering whether you can actually just use the nuBuilder object names or some other extra syntax is required.
I couldn't really find which naminig convention to use from the F12 developer option.
-
- nuBuilder Team
- Posts: 4292
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 444 times
- Contact:
Re: Search2 Select Object
Just use the nuBuilder object id. It works for me:
You do not have the required permissions to view the files attached to this post.
-
- Posts: 19
- Joined: Fri Mar 22, 2024 4:59 pm
Re: Search2 Select Object
That also works for me...
It was the dynamic option creation that I couldn't see how to implement:
https://select2.org/tagging
It was the dynamic option creation that I couldn't see how to implement:
https://select2.org/tagging
-
- nuBuilder Team
- Posts: 4292
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 444 times
- Contact:
Re: Search2 Select Object
To enable tags for Select2 objects, use the PHP BE event. You can use the following code snippets.
Enable tags for all Select2 objects on a form:
Enable tags for a specific Select2 object with ID "mySelectObjectId":
Replace `'mySelectObjectId'` with the actual ID of your Select2 object to apply tags only to that specific instance.
Enable tags for all Select2 objects on a form:
Code: Select all
$js = "
window.nuOnSetSelect2Options = function(id, objSelect2OptionsDefault) {
// Customize Select2 options here
let customOptions = {
tags: true // This enables tags mode in Select2
};
return customOptions;
};
";
nuAddJavaScript($js, true, true);
Enable tags for a specific Select2 object with ID "mySelectObjectId":
Code: Select all
$js = "
window.nuOnSetSelect2Options = function(id, objSelect2OptionsDefault) {
if (id === 'mySelectObjectId') {
let customOptions = {
tags: true
};
return customOptions;
}
return {};
};
";
nuAddJavaScript($js, true, true);
Replace `'mySelectObjectId'` with the actual ID of your Select2 object to apply tags only to that specific instance.
-
- Posts: 19
- Joined: Fri Mar 22, 2024 4:59 pm
Re: Search2 Select Object
Hi Kevin,
Great, this works!
I definitely would not have got there by myself!
Is there any documentation regarding this and similar options... or perhaps I need to be more knowledgeable about Javascript?
Cheers,
Alan
Great, this works!
I definitely would not have got there by myself!
Is there any documentation regarding this and similar options... or perhaps I need to be more knowledgeable about Javascript?
Cheers,
Alan
-
- nuBuilder Team
- Posts: 4292
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 444 times
- Contact:
Re: Search2 Select Object
All available config options are documented here: https://select2.org/configuration/options-api
However, the snippet I posted (esp. window.nuOnSetSelect2Options) is not documented yet.
However, the snippet I posted (esp. window.nuOnSetSelect2Options) is not documented yet.