Skip to content

Allow ternary v-bind:type with v-model. #6158

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

Closed
nickmessing opened this issue Jul 18, 2017 · 7 comments
Closed

Allow ternary v-bind:type with v-model. #6158

nickmessing opened this issue Jul 18, 2017 · 7 comments

Comments

@nickmessing
Copy link
Member

What problem does this feature solve?

There is common "Show Password" pattern today and we have to use v-if/v-else for that. Can we consider allowing ternary expression that returns only one of text,number,password,search,email,tel,url allowed in v-bind:type?

What does the proposed API look like?

<input :type="showPassword ? 'text' : 'password'" v-model="text">
@javoski
Copy link
Member

javoski commented Jul 19, 2017

I suppose this is supported.
https://jsfiddle.net/xujiongbo/phgx2s2o/1/

@nickmessing
Copy link
Member Author

Whoops, sorry, missed that.

@nickmessing
Copy link
Member Author

Oh, check the console, we have [Vue warn]: Error compiling template

@nickmessing nickmessing reopened this Jul 19, 2017
@javoski
Copy link
Member

javoski commented Jul 19, 2017

When switching input types between text, number or file, it will lead to some strange behaviors because the format of model value doesn't match the type.

@nickmessing
Copy link
Member Author

nickmessing commented Jul 19, 2017

@javoski, file - yes, that's why we have a list of text-like inputs as I mentioned in description (text,number,password,search,email,tel,url)

P.S. number works as text and value is string. (example: 00)

@mosinve
Copy link

mosinve commented Jul 28, 2017

Another way to do this clearly at current release, is to avoid ternary, for example:
https://jsfiddle.net/cihkem/103b96fr/

As was written at some VueJS CodeStyle Guide, it;s better to try to use simple expressions at components attributes and move complex ones to a callback functions

@yyx990803
Copy link
Member

We will likely support full dynamic type for v-model in the next minor release, so closing this one for now.

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

No branches or pull requests

4 participants