Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined ngModel adds a null dropdown option, doesn't diplay the placeholder, and breaks typing #20

Open
conoremclaughlin opened this issue Sep 1, 2014 · 3 comments

Comments

@conoremclaughlin
Copy link

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?

@conoremclaughlin
Copy link
Author

after looking it over - this follows angular.js's standard select behaviour (which is silly IMO but oh well!). sorry to be a bother!

@EvanOxfeld
Copy link
Owner

@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.

@EvanOxfeld EvanOxfeld reopened this Sep 3, 2014
@EvanOxfeld EvanOxfeld changed the title Initializing ng-model to a null value adds a null dropdown option and breaks typing Undefined ngModel adds a null dropdown option, doesn't diplay the placeholder, and breaks typing Sep 3, 2014
@kernel-io
Copy link

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();

screen shot 2015-05-18 at 3 55 14 am

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

screen shot 2015-05-18 at 3 56 05 am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants