ui-select
ui-select copied to clipboard
tagging function with array of string not working
I want to limit the tag creation for string with length < 2 but I always get this error:
Uncaught TypeError: Cannot create property 'isTag' on string
this is the tagging function:
vm.tagging` = function (text) {
if(!text || text.length < 2)
return null;
return text;
};
and here is a plunker: http://plnkr.co/edit/SS3V4A13nAbPDRAYrdaI?p=preview
You can see the error in the console and the new tag is not created. I suppose the error is because he expect an object to be returned from that function and I return a string. I dunno how to limit the creation of tag with an array of string and I really need this.
Had a look at you plunker, i'm not getting the error or i'm doing something wrong. Can you verify if the plunker has the correct example?
I verified and I still get the error. Try to write "hello" inside the input and press Enter:
- The tag "hello" will not be created (in fact in the dropdown it does not appear) and the first element in the dropdown is added (in my case "Red")
- If you open the console (F12 in chrome, tab console) you'll see the error.
I had the same issue, here is how I made it works:
<ui-select multiple tagging="myScopeFunction" (...)
with:
myScopeFunction = function(newItem) {
return {
label: newItem,
value: newItem,
}
}
It will generate the correct values in the ngModel (array of strings).
Same issue here, but trying the approach suggested by @poupougnac doesn't work for me. The javascript error goes, but the value that is displayed in the dropdown list is the entire object.