selectize.js icon indicating copy to clipboard operation
selectize.js copied to clipboard

Allow duplicate values in an input

Open jbrooksuk opened this issue 10 years ago • 50 comments

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.

jbrooksuk avatar Sep 24 '13 16:09 jbrooksuk

Version 0.8 will allow this - if I understand your issue correctly - have a look at issue #76

flamber avatar Sep 25 '13 16:09 flamber

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.

jbrooksuk avatar Sep 25 '13 16:09 jbrooksuk

Any news on this?

jbrooksuk avatar Oct 01 '13 10:10 jbrooksuk

Try last version.

FoboCasteR avatar Oct 24 '13 07:10 FoboCasteR

@FoboCasteR am I needing to use any new settings? It's not working by default.

jbrooksuk avatar Oct 24 '13 12:10 jbrooksuk

#76 - Here I used standalone version. Works fine with default settings.

FoboCasteR avatar Oct 24 '13 13:10 FoboCasteR

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.

jbrooksuk avatar Oct 24 '13 14:10 jbrooksuk

+1

@jbrooksuk did you ever find a solution to this?

ohaibbq avatar Nov 20 '13 02:11 ohaibbq

@OhaiBBQ, I'm afraid I never did.

jbrooksuk avatar Nov 20 '13 09:11 jbrooksuk

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. :)

airwin avatar Nov 27 '13 03:11 airwin

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 avatar Dec 18 '13 04:12 Inateno

@Inateno that's exactly what I want.

jbrooksuk avatar Dec 18 '13 07:12 jbrooksuk

@Inateno nice solution~!

airwin avatar Dec 18 '13 08:12 airwin

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 avatar Jan 06 '14 21:01 xdbr

@xdbr there‘s not an official solution yet, u can use @Inateno 's code above.

airwin avatar Jan 07 '14 09:01 airwin

@airwin: thanks, of course @Inateno's solution works nicely, my very stupid bad...

xdbr avatar Jan 08 '14 11:01 xdbr

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

xdbr avatar Jan 08 '14 12:01 xdbr

@brianreavis have you had any thoughts about this?

jbrooksuk avatar Feb 26 '14 11:02 jbrooksuk

I've made a PR that fixes this.

jbrooksuk avatar Mar 10 '14 10:03 jbrooksuk

will it be merged in master branch?

msangel avatar Sep 17 '14 02:09 msangel

What's the status about that?

jmav avatar Oct 29 '14 18:10 jmav

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 avatar Oct 30 '14 05:10 Anxy

@Anxy you'll need to use the right branch; https://github.com/BlueBayTravel/selectize.js/tree/allow-duplicates

jbrooksuk avatar Oct 30 '14 07:10 jbrooksuk

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. ;)

thehonestcto avatar May 21 '15 15:05 thehonestcto

Is there any other library that allows this?

ben-pr-p avatar Oct 16 '15 21:10 ben-pr-p

+1 for this functionality. This is really desired enhancement.

krassowski avatar Feb 17 '16 11:02 krassowski

Reminder: you can vote for this issue by adding a +1 emoji at the top.

PR #324 was attempted, but then abandoned.

joallard avatar Jun 22 '16 20:06 joallard

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...

quarantaquatro avatar Jul 20 '16 04:07 quarantaquatro

I use the repository above. I can add the duplicates values but when editing values do not appear as a duplicate.

konradb90 avatar Aug 04 '16 16:08 konradb90

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.

bedeio avatar Feb 22 '17 20:02 bedeio