I want to have a dropdown with a set of values but also allow the user to \"select\" a new value not listed there.
I see that select2 supports this if you are using
Improvent on @fmpwizard answer:
//Allow manually entered text in drop down.
createSearchChoice:function(term, data) {
if ( $(data).filter( function() {
return term.localeCompare(this.text)===0; //even if the this.text is undefined it works
}).length===0) {
return {id:term, text:term};
}
},
//solution to this error: Uncaught TypeError: Cannot read property 'localeCompare' of undefined
I just stumbled upon this from Kevin Brown. https://stackoverflow.com/a/30019966/112680
All you have to do for v4.0.6
is use tags: true
parameter.
There is a better solution I think now
simply set tagging to true on the select options ?
tags: true
from https://select2.org/tagging