Load from the server which values are selected
BobDJ opened this issue · 2 comments
Hello Patrick, thank you for your awesome work.
I have been working with your multi select in some projects and it works like a charm. However, I have an issue that I can't solve, maybe you can show me how to proceed.
I am using your multiselect to create a filter system, so, in the end, I just take the different selected values of each multiselect and save it on the server, however, when I want to load them on the web page they should be selected values. Is there any kind of way to say "make this list selected and maintain the rest unselected"
Thank you for your help
So I don't fully follow what you are doing but I see a couple of things that might be it.
If you are loading the options into the list VIA javascript then the "checked" value is what you are looking for:
// DYNAMICALLY LOAD OPTIONS
$('select[multiple]').multiselect( 'loadOptions', [{
name : 'Option Name 1',
value : 'option-value-1',
checked: false,
attributes : {
custom1: 'value1',
custom2: 'value2'
}
},{
name : 'Option Name 2',
value : 'option-value-2',
checked: false,
attributes : {
custom1: 'value1',
custom2: 'value2'
}
}]);
However if you are just wanting options that are loaded in the element on page load then you just need to add the selected="selected" attribute to the element that is to be selected.
Thank you very much!! I was using since I started the dynamically load options but I didn't know that I was able to add a new attribute and reload it.
Best Regards