Closed SB401 closed 5 years ago
So the add option functionality already exists. You would want to use the loadOptions method. There is an example "DYNAMICALLY ADD OPTION TO LIST" on my demo site.
The ability to limit to a single option selected can be done using the onOptionClick callback. There is an example in issue #43.
As far as jQuery Validate I am not familiar with it nor am I sure what changes within the code refers to it. Is that the changes from the .prev & .next to .siblings? Maybe you can elaborate a little more?
FYI: I am usually hesitant on adding new "features" to this plugin. My thought process for this plugin is something that is simple but give the developer the ability to customize as they require. I had looked at many other select plugins but they were usually overbuilt for my needs.
I first could not get jQuery Validate to work when using your multiselect. I ask for assistance on stackoverflow (https://stackoverflow.com/questions/51462649/how-to-use-jquery-validation-together-with-jquery-multiselect-plugin) and was advised to set ignore: ':hidden:not("#mySelect")'. This worked to some extent. But I noticed that the div create by jQuery Validate lodged between the select and .ms-options div preventing the .prev & .next from working. .siblings seemed to do the trick.
As regards add option I wanted to add option when not available from search. The value in the search box is then added to the option. The add option button is also inside the .ms-options. See example on the site I am currently developing (http://wowislandcharter.com/roit/)
As I said before your multiselect is great out of the box. I just posted my modification just in case it may be of some use.
Cheers
So I fixed the issue with the $.prev()
& $.next()
usage that was causing your jQuery validate bug. I opted to make a slight alteration as I want to guarantee that the proper sibling is targeted and not that of another list.
I am not sure I want to add the add item functionality, however I feel like it might be able to be added on your end using the onLoad callback.
Thanks for addressing this issue. You are a champion.
Hi Patrick,
I have been using your multiselect on a couple of projects know and I absolutely love it. However, I had to make a few addition to your code to suit my needs and I am happy to give you the modified code as a contribution. I am a self thought coder and my codes are a bit messy but they work.
Additional features are:-
Adding new option to select element Example $("#foodconsumed").multiselect({
columns:2, search:true, texts:{placeholder:"SELECT FOOD CONSUMED"}, searchOptions:{addnewitems:"addfood"}
})
addfood is a javascript function that runs when you click the button which is created in .ms-options when addnewitems is set to true
Below is the modified code with comments to show where I have made the modifications: