Selectize.js: Allow duplicate values in an input

Created on 24 Sep 2013  ·  42Comments  ·  Source: selectize/selectize.js

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.

consensus on need enhancement pending review pull request welcome

Most helpful comment

Same here, this really should be included.

All 42 comments

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.

I would be interested in this functionality, too (and using the "official" version)

Same here, this really should be included.

Since the above branch has been removed, is there a current solution for this?

Why has the branch been removed?

In my countries.sql, I have 246 countries but only 227 international phone code numbers. This means I can't use selectize for choosing country codes.

closing stale issues older than one year.
If this issue was closed in error please message the maintainers.
All issues must include a proper title, description, and examples.

Sorry, but why is this closed? Such a long discussion with including samples, proposed fixes and so on. What's the reason of closing it without actually doing it?

Sorry, but why is this closed?

With the project being unmaintained for such a long time, our current focus is regaining a fair baseline and assessing items based on activity. The only fair way of doing this is by bulk closing items without any major activity and re-opening on request.

(side note, this shouldn't have been caught in that filter; sorry)

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

This issue still need a fix

It would be great to have the duplicate values capacity added or resolved. Great software, thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jaideepYes picture jaideepYes  ·  5Comments

daveedwards45 picture daveedwards45  ·  3Comments

vilimco picture vilimco  ·  5Comments

IAmJulianAcosta picture IAmJulianAcosta  ·  5Comments

John-Fratila picture John-Fratila  ·  4Comments