-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Dynamic select directive doesn't support empty value #11470
Comments
So your issue is that the |
Yes, that's right... |
So the design of this directive is that the empty option should be hard-coded - even if the rest of the options are loaded from the server. Could you try doing that as a workaround? |
Unfortunately no, because even display for this empty value should has to come from server. I have simple ng-repeat that iterates options I get from server and display can be different depending on place this directive is used. |
If you agree, we can do in this line additional check if emptyOption is not defined, try to search for it:
I would search it in the way initial search is done:
It would be a pleasure to do pull request on this... |
I would rather not search every time. Perhaps we could come up with a solution that allows a new "empty" option to register itself when it arrives... |
In that case you will have two empty options :) The problem here is that emptyOption reference is not defined in the moment we would use it. If you see, it enters this part of condition by checking:
so it's already there. Only thing, it's not bind to emptyOption variable causing it to throw exception. |
OK, here is suggested fix. In addOption, which is being called each time option is created, we can check if value is '' and store that into self.emptyOption? Quick fix, what do you think? Did I forget to mention, it's branch 1.2.X. |
That could work. Do you want to try to create a Pull Request, with tests and docs? |
Yeah sure. I'll do it, will take a look tomorrow |
…y put it inside select (issue angular#11470)
I did pull request, can you review? Thanks! |
Hi @petebacondarwin , is it maybe something wrong with my pull request? If so, can you tell me what it is and I'll change it? Thanks |
Sorry I will take a look this week. |
Thanks! |
…y put it inside select (issue #11470)
The select directive supports provision of an "empty" element that is used if the value of the select is undefined. This fix ensures that this empty option can be provided dynamically after the initial compilation has completed. Closes angular#11470 Closes angular#11512
…y put it inside select (issue angular#11470)
Branch 1.2.X issue.
In case I have select directive which get options generated from server, it throws following error:
in case I'm trying to update model in my test (it works perfectly fine when it comes to browser, but it can't update itself based on model change) and here's why. This piece of code executes when linking select initially:
and in this moment of course, my select doesn't have emptyOption. Later on, I populate options and try to update model in my test. Then this piece of code is triggered:
Now, in this moment emptyOption is undefined, but I really do have it, only thing, it was generated later (after link function).
Can we(I can do it if you let me) have additional element.find when it comes to assigning to emptyOption?
The text was updated successfully, but these errors were encountered: