-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
conditional change of <input> type attribute not working. #6313
Comments
Using Why is it not dom-diffing and applying the change only to the attribute value like one would expect? |
Here's the same thing, broken, using a self-closing input tag: https://jsfiddle.net/trusktr/50wL7mdz/52202/ |
Here's a fiddle showing that it works with vanilla HTML/JS: https://jsfiddle.net/trusktr/50wL7mdz/52205/ This raises the concern that Vue is not dom diffing like it claims. If it were, then only the |
@syropian suggested to add a dummy |
@trusktr, because |
@nickmessing That's not intuitive, please fix. This is the sort of thing that should work in Vue because it works in the browser. Sure, switching from But switching to |
Do you not see the fact that someone telling me to unituitively use v-model as a workaround is a problem? It is frustrating when a library's issue gets closed if the library author can easily improve the library for the benefit of all the users at the cost of a small one-time extra effort on the library author's side, and when the library author chooses perhaps author convenience over true benefit of the user. You could instead leave this open and suggest a PR he made. That's much better a choice. |
@trusktr, Well, re-rendering diffs indeed, let's imagine a simple scenario. <input type="text" /> Step 2. You add some text, DOM looks like (consider that <input type="text" domProp-value="asdasd" /> Step 3. You change <input type="text" domProp-value="asdasd" />
<input type="password" /> Result: value gets removed. This is intuitive if you understand virtual dom based re-rendering. It does remove |
That example isn't really applicable to my case, and you also mentioned some implementation details that end users don't need to care about. The case is simple: if the only thing changing is type Another way to put it is: if I can simply change from type Honestly this is good enough reason to make this optimization on your end, in this case and any other similar cases, to make it as intuitive as possible for end users. |
I've updated the title to remove the question mark. Even with the This is REALLY bad. This destroys interoperability with outside code. For example, bootstrap validator stops working because it will have a reference to a no-longer-existing If Vue is supposed to be incrementally adoptable, and interoperable with outside code (f.e. jQuery plugins) then this simply is not acceptable. |
If Vue is always dom-diffing like it claims, here’s a fiddle that should work: https://jsfiddle.net/trusktr/50wL7mdz/52661/ Start typing in the input field, and you will see the values logged to console. Then, when you toggle the show/hide of the password, if Vue were dom-diffing properly, it would be changing only the But this isn’t the case because now there’s no input in the console. Each time the show/hide is toggled, Vue replaces the entire This broke the simple |
Here’s the same example, using React, and dom-diffing works as expected: https://jsfiddle.net/trusktr/69z2wepo/84211/ |
@trusktr, It indeed makes sense to change the Vue was never claiming |
True, but some guarantee of atomicity can be proposed regardless of implementation: if only an attribute is supposed to change based on the Vue template, then the only thing in DOM that should change is the corresponding real attribute.
It's probably suboptimal to ever replace the input no matter what the type transition. When changing type from text to file, DOM changes In any case, I don't think there's any need to replace the input element regardless of which type change happens, because you simply can't predict what the user is doing or why, and it is fair for Vue not to make those assumptions (even if unintentional). |
Here's a fiddle that shows I think it is the interest of a tool to work with existing standardized DOM functionality, not working against expectations of how DOM works. |
FYI this is an intentional mechanism for dealing with Toggling between |
Version
2.4.2
Reproduction link
https://jsfiddle.net/trusktr/50wL7mdz/52198/
Steps to reproduce
Try to type in the text field. It will keep clearing your input every second.
What is expected?
It should toggle between showing and hiding the password.
What is actually happening?
It is destroying the input (or clearing its value) each time the value of
hidden
changes.The text was updated successfully, but these errors were encountered: