Allow duplicate values in an input
Is it possible to have an input element which allows duplicate values? The reason is, I'm trying to build a form which allows people to enter ages of children, which can of course, be the same; twins, triplets etc.
Version 0.8 will allow this - if I understand your issue correctly - have a look at issue #76
Not quite.
Say I have an input element with the values 1-17. I need to be able to select any number in that range multiple times. So after I've finished picking my values, I could end up with 1, 1, 3, 5 as the output.
Any news on this?
Try last version.
@FoboCasteR am I needing to use any new settings? It's not working by default.
#76 - Here I used standalone version. Works fine with default settings.
No. This wasn't what I meant.
My problem doesn't involve optgroups. I just need to be able to select the same value more than once.
+1
@jbrooksuk did you ever find a solution to this?
@OhaiBBQ, I'm afraid I never did.
i think this issue may need to have some modification to the selectize.js file
steps(with selectize v0.8.5):
1:make the selected items can be duplicate when “create” line:2494 CHANGE: addItem: function(value) { TO: addItem: function(value, is_create) {
line:2502 CHANGE: if (self.items.indexOf(value) !== -1) { TO: if (!(is_create && self.settings.enableCreateDuplicate) && self.items.indexOf(value) !== -1) {
note here i add a new option in settings named “enableCreateDuplicate” to switch this feature
2:sign as an user-create item in the createItem function line:2625 CHANGE: self.addItem(value); TO: self.addItem(value, true); // sign as an user-create item
3:add the new options where init selectize $(select).selectize({enableCreateDuplicate: true});
now it should can accept duplicate values when create. try it. :)
EDITED (my bad coding the night huehue) so.
So, I got the same problem than @jbrooksuk and solved it. You were right @airwin but this work only when you create an entry it's not perfect to work like I wanted (and I think like he wanted) and I didn't have what you are saying at the same line... :/ with the 0.8.5.
Just to be sure we are speaking about the same thing this code is to made possible to add the same searched value (so duplicated). I think some people here didn't understood @jbrooksuk request. Little example, if you have [ "hello", "banana", "potatoes" ] as possible results, we wanted to be able to select 2 or 3 times hello, so our result could be [ "hello", "hello", "banana", "hello" ].
Hope is that you were looking for, I didn't wrote all of this for nothing xD
So code (I'll give my lines, but maybe it's different, don't care, just search the same thing). We don't need the "is_create" bool because we want to allow duplicate entry on search and on create.
LINE 1686 in the addItem function scope replace the if(self.items.indexOf(value) !== -1) by if ( !self.settings.enableDuplicate && self.items.indexOf(value) !== -1 ) This will allow to push a value that already exist ine your values
Now, after a long search inside the code (ok I just see it in the doc/usage, but looked before xD), there is an option to let the values already used. set hideSelected: false when init your selectized item.
With this option and the new enableDuplicate, you will see them in the list, and will be able to add them again.
Done that's all. I want to "stack" duplicatas in the same result by adding a xN prefix, I'll see how to do this ^^
Maybe pushing it in the next release ? It's not heavy and very usefull in my opinion.
@Inateno that's exactly what I want.
@Inateno nice solution~!
Same use case here as @jbrooksuk ( @jbrooksuk: did you get the hacks outlined above to work for you?).
Judging by looking at the code as of 0.8.5 I can see changes that hint me towards there being an option inputMode: multi/single. However this is not mentioned in the documentation (usage.md).
Now I am confused whether this is already resolved and this issue to be closed as of 0.8.5 or not? How would I have to go about multiple values, as in @Inateno's example?
@xdbr there‘s not an official solution yet, u can use @Inateno 's code above.
@airwin: thanks, of course @Inateno's solution works nicely, my very stupid bad...
As a heads up: I forked and tried to integrate the solution outlined above to be able to offer a pull request. However, the grunt builds don't work, because of #232 which itself is blocked by this
@brianreavis have you had any thoughts about this?
I've made a PR that fixes this.
will it be merged in master branch?
What's the status about that?
Use this version: https://github.com/BlueBayTravel/selectize.js
It works like a charm, in option give Boolean for: duplicates: true/false
Hope this helps!
From: Jure [mailto:[email protected]] Sent: Wednesday, 29 October 2014 11:32 PM To: brianreavis/selectize.js Cc: Anxy Subject: Re: [selectize.js] Allow duplicate values in an input (#129)
What's the status about that?
— Reply to this email directly or view it on GitHub https://github.com/brianreavis/selectize.js/issues/129#issuecomment-60973527 . https://github.com/notifications/beacon/AH1BxSC0nbe2N_zsgjzMSRr80a6qSoiEks5nISMdgaJpZM4BB7xD.gif
@Anxy you'll need to use the right branch; https://github.com/BlueBayTravel/selectize.js/tree/allow-duplicates
Ah, we really need this feature too. It looks like a small fix. Why isn't added in the main release? It's very useful! Thank you in advance! And...by the way, great piece of software. ;)
Is there any other library that allows this?
+1 for this functionality. This is really desired enhancement.
Reminder: you can vote for this issue by adding a +1 emoji at the top.
PR #324 was attempted, but then abandoned.
Thanks to all of you guys for this tips. I used as well https://github.com/BlueBayTravel/selectize.js/tree/allow-duplicates and it worked perfect for me. I just changed the following defaults:
hideSelected: false, // from original null duplicates: true, // from original false
this has saved me a lot of headache. I used my own code before but had some trouble with it and by coincidence I found this post here. thx...
I use the repository above. I can add the duplicates values but when editing values do not appear as a duplicate.
Are pull requests being accepted for this issue? I have been using BlueBayTravel's branch (https://github.com/BlueBayTravel/selectize.js/tree/allow-duplicates), but would like to use the "official" version.