-
Notifications
You must be signed in to change notification settings - Fork 354
Implementing "input's type property CAN be changed" #371
Conversation
This directive enables to write an input tag with a variable type property like: <input type="{{model}}" ui-input2 /> You can not write the following code without this directive: <input type="{{model}}" /> because jQuery throws an error: "type property can't be changed" when an type property is dynamically changed. This is due to an IE problem: http://stackoverflow.com/questions/1544317/jquery-change-type-of-input-field
@mikoto does your version work on IE? AFAIK IE doesn't allow changing of input types... |
The answer is Yes. |
For testing, I loaded a jQuery on the line 9 in http://plnkr.co/edit/Ddp8prhsKsKRhPL8uYLc. |
I foresee problems when working with other directives. You should possibly replace the node with a comment placeholder at compile time (not linking time). Then render out upon linking |
Dean is right that you have to be careful when replacing elements. If you On 21 January 2013 18:35, Dean Sofer [email protected] wrote:
|
omg! Sorry, I uploaded wrong version of my codes.(It does not work on IE because of using attar() method for type property.) |
Thanks for your advices. you are correct. I have to be careful with replacing element on/after a link step. But to solve the problem "type property can't be changed" needs to watch type property changes because we can not change type property of input tag. So, my solution is "recompile" the input tag after replacing by using $compile(http://docs.angularjs.org/api/ng.$compile) function. |
@petebacondarwin, I want to confirm order of compiles and links step. All link steps run after all compile steps, right? Otherwise, for example, we have directiveA(has compileA and linkA) and directiveB(has compileB and linkB), Back to my motivation. |
@mikoto - I find this example useful : http://plnkr.co/edit/qrDMJBlnwdNlfBqEEXL2?p=preview So you can indeed copy attribute values from the current element to any that you decide to replace it with. But what is a bit more difficult is copying the "behaviour". In other words any bindings that have been set up between the element and its scope and any controllers that have been attached to the element. In the link function, the following siblings of the element have not yet been linked and if you start adding siblings after then the compiler will get confused and try to link those instead of the elements that it expects to be there. Worse still if you try to add a sibling before this element, the the compiler will get in an infinite loop because it will then try to link this element over and over again! |
@petebacondarwin, Thank you so much! Now, I close this pull request. |
This directive enables to write an input tag with a variable type property like:
You can not write the following code without this directive:
because jQuery throws an error: "type property can't be changed" when an type property is dynamically changed.
This is due to an IE problem: http://stackoverflow.com/questions/1544317/jquery-change-type-of-input-field