Hello Everyone!
Searched all over the forum about user Select2 to update values but was not able to solve my problem.
I have a partial with a select2 that is inserting values on database correctly, I’m storing the data as CSV.
On the top of partial, I’m adding this code (using a css library to select2 work with boostrap):
<script>
$(document).ready(function () {
$('.check-multiple').select2({
theme: "bootstrap"
});
</script>
To retrieve the infos already on the database, when clicking on <li>
tag, on “Static Event” OnClick, I call this script + load a server connect:
<script>
function myfunc() {
console.log(dmx.parse('conn_findone_servicefeature.data.qry_find_one_servicefeature.service_feature').split(","));
$('.check-multiple').val([dmx.parse('conn_findone_servicefeature.data.qry_find_one_servicefeature.service_feature').split(",")]).trigger('change');
}
</script>
When debugging on Chrome, I got this error:
When I replace “dmx.parse” for values already on my database, for example: [4,5,6], the tags are displayed.
The SC is retrieving data correctly when clicking on the <li>
tag.
Thanks in advance and have a great week!
1 Like
Make sure the path to the server connect in your dmx.parse command is correct by checking dmx.app.data in the dev console. For example I always forget to add content. before server connects contained within content views.
1 Like
Hey Ken! Thanks again for your help! You nailed it!
BUT when I have more than one value returned, for example: 2,3, nothing is displayed, only fields with unique values…plus, I follow some tips from another post and changed my script to:
<script>
function myfunc() {
$(".check-multiple").select2();
setTimeout(function () {
$(".check-multiple")
.val([
dmx.parse('content.conditional_services.conn_findone_servicefeature.data.qry_find_one_servicefeature.service_feature').split(",")
])
.trigger("change");
}, 100);
}
</script>
Why when multiple values doesn’t show the tags?
Thanks, mate!
I actually use select2 differently than the example you provide, so I can’t quickly compare the syntax for you. And I’m without power today, so I can’t test what you are doing.
Don’t worry! When you have a time, let me know!
Teodor
March 10, 2022, 4:38pm
6
Multi select is now available in Wappler, thanks to the Tagify component:
See:
Intro
The Tagify component transforms an input field into a Tags component , in an easy, customizable way, with great performance and many customizable options. Tagify provides auto suggestions when entering text into the input - really useful dynamic list of products, countries, options etc., so you can offer your users quick search and selection without having to enter long text.
In this tutorial we will show you the basics of the component.
Add Tagify on the Page
We added a form on the pa…
1 Like