How do I reload the values of multiple select boxes with jQuery StickyForms?
-
11-10-2019 - |
Question
I'm using jquery stickyForms to make some form values sticky, so that the user's entered values are restored to a form when the user returns to that form.
It's works great, except I can't get it to work with my multiple selects. I checked the cookies it creates, and it doesn't even set the right values. Looking at the code, it doesn't even appear to support multiple selects.
Can anyone help?
Solution
I took it upon myself to add support for multiple selects. This works for me!
I changed line 115 to:
}else if(this[i].type == "select-multiple"){
var setVal = $(this[i]).val();
}
Then I added this after line 178:
// Load multiples
if((this[i].type == "select-multiple") && val != "null" ){
var val_list = val.split(",");
var select_name = "#" + $(this[i]).attr("id");
$(val_list).each(function(){
$(select_name + " option[value="+this+"]").attr('selected','selected');
});
}
It works! But mind you, I'm not an expert at javascript or jQuery, so if you have a more succinct solution or one with better performance, please let me know!
OTHER TIPS
This is Ryan from JQByte, I wanted to let you know that we released version 1.0 of StickyForms today which includes support for multi-select and AJAX-processing forms.
http://www.jqbyte.com/StickyForms/
We did incorporate your solution into the plugin, we thank you for your contribution!
Cheers, Ryan