I am using a select box from ui-select. All is working fine, but I want to allow manually entered text and do not want to restrict the user from the values available in the
I think I found a way to allow the user to create new entries. Use the "on-select" attribute to pass a function that takes $select as a parameter as below:
{{$select.selected.name}}
Then create the function that adds a new entry when the clickTriggeredSelect variable is false:
$scope.peopleSel= function(sel) {
if ( sel.search && ! sel.clickTriggeredSelect ) {
if ( ! sel.selected || sel.selected.name != sel.search ) {
//Search for an existing entry for the given name
var newOne= personSearch( sel.search );
if ( newOne === null ) {
//Create a new entry since one does not exist
newOne= { name: sel.search, email: 'none', country: 'unknown' };
$scope.people.push( newOne );
}
//Make the found or created entry the selected one
sel.selected= newOne;
}
}
sel.search= ''; //optional clearing of search pattern
};
Note that personSearch definition is not provided here. Also this approach of testing the clickTriggeredSelect can be used to allow the user to unselect the field if a blank entry is the preference.
PVC