I'm building a select where the user can choose its country (and it will get the country code).
Vatican and Italy have the same code (39) and selectize shows only Vatican, I think this problem should be solved and you should allow options with the same value.
I second this. I am using selectize for address searches (on street and city level). But I use the street name as valueField for the input element because the web is supposed to work even without the Javascript (and you can create new address). The onItemAdd function then updates hidden locationId field and the fields for city, zip, ... when a known address is selected.
Obviously, the street name can happen multiple times and selectize filters the "duplicate" occurences out which breaks my workflow.
Look at issue #129
No that's not my problem.
I've:
<select>
<option value="a">foo</option>
<option value="a">bar</option>
</select>
And I want to have both the options visible.
Then #129 is exactly your problem, since Selectize currently doesn't support duplicate values.
I see in this comment that they want to be able to select multiple times the same value.
https://github.com/brianreavis/selectize.js/issues/129#issuecomment-30816738
So they want:
<select>
<option value="a">foo</option>
<option value="b">bar</option>
</select>
selection: foo, foo, bar, foo
Yes, but to allow dupes in Items, it needs to be able to handle dupes in Options. It's interconnected.
You have two quick fixes, if you don't want to mess with the Selectize core. Either write "Italy / Vatican" for value 39 or add an ID to get value, which you strip away before saving it to your database.
<select><option value="39">Italy / Vatican</option></select>
<select><option value="39-124">Italy</option><option value="39-318">Vatican</option></select>
I think I'll write a more lightway library from scratch, I'm facing too many troubles with this one.
Thanks however.
Maybe typeahead.js is more your tune - https://github.com/twitter/typeahead.js
I think you can edit like here
registerOption: function(data) {
var key = hash_key(data[this.settings.valueField]);
// if (!key || this.options.hasOwnProperty(key)) {
// console.log(key);
// return false;
// }
data.$order = ++this.order;
this.options[data.$order] = data;
return key;
},
Just ran into this. HTML allows multiple options with the same value, so not supporting that in selectize violates the principle of least astonishment/surprise.
Are there reasons that selectize _shouldn't_ or _can't_ support this behavior, or is it just a matter of needing someone to do the work?
Thanks!
Actually Problem seems to be in way selectize use its data object. selectize.options
which store value as
{ "input value" :{
$order: " selectize.order incrementer, its incremented every times a new option is created.",
text: "Input value",
value: "input value"
}
}
since value is made property key of an javaScript object and every key must be unique , so Options with same value is failing. Creator of this plugin must use some different approach to store options to allow two options with same value.
I didn't understand much, but I'm closing in favor of #129. If this concerns another issue, please open a new one with a minimal example and STR.
Most helpful comment
Just ran into this. HTML allows multiple options with the same value, so not supporting that in selectize violates the principle of least astonishment/surprise.
Are there reasons that selectize _shouldn't_ or _can't_ support this behavior, or is it just a matter of needing someone to do the work?
Thanks!