angular-selectize.js
angular-selectize.js copied to clipboard
Undefined ngModel adds a null dropdown option, doesn't diplay the placeholder, and breaks typing
appreciate your work on this!
it looks like the behaviour requires an initial value must be set on the model. this isn't ideal if we're trying to show off a placeholder first as well as force the user to make an explicit choice.
an example secnariowould be choosing their country for a telephone number.
following code:
select(selectize, placeholder="Choose a country", ng-model="user.nationality", ng-options="country.name for country in countries")
Unless user.nationality has been initialised to one of the choices, this breaks the typeahead of selectize and adds an empty row. Any advice on how to proceed?
after looking it over - this follows angular.js's standard select behaviour (which is silly IMO but oh well!). sorry to be a bother!
@conoremclaughlin Thanks for the feedback -- it's not a bother at all. Even if I wasn't reopening this issue.
Angular-selectize supports the placeholder attribute, however, the model has to be explicitly initialized to null for the placeholder to be displayed. An undefined model should display the placeholder and not add an empty row. In this instance I don't think it makes sense for the selectize directive to follow Angular's standard behavior.
this was really pissing me off, so I hacked up a solution which fixes it for me.
haven't tested all edge cases but it works so far for me
$timeout(function(){
selectize.removeOption('? object:null ?');
selectize.removeOption('? undefined:undefined ?');
},0);
put this on line 155, right after syncInputClasses();
Here is how it looks in action, it will work if the model is undefined or null, i use ng-repeat to generate my options so YMMV