Vue: Boolean attributes

Created on 15 Jan 2016  ·  9Comments  ·  Source: vuejs/vue

According to the HTML5 spec:

The values "true" and "false" are not allowed on boolean attributes. To represent a false value, the attribute has to be omitted altogether.

So, in order to make my code spec compatible, i'd do in this way in vue: <input :checked="checked ? '' : false">, do you think it is necessary to directly support boolean attributes in vue? @yyx990803

Solutions I can think of are these:

  • By another directive: v-add:selected="true" (not recommand)
  • By modifier: v-bind:selected.boolean="true" (recommand)
  • Auto: v-bind:selected="true", we need to mantain a boolean attribute list(see), and this may have compatibility problems.

Again, if you think it is necessary, let me handle this! :trollface:

feature request

Most helpful comment

What's the problem with <input :checked="checked">? Vue removes the attribute if checked is falsy.

All 9 comments

What's the problem with <input :checked="checked">? Vue removes the attribute if checked is falsy.

Well, <input checked="true"> and <input checked="1"> are invalid in HTML(although they can work in most browsers), only <input checked> and <input checked="checked"> are valid.

Ok, I guess the modifier is the best way to go. Should be easy too. PR welcome :)

What about the modifier name? is .boolean ok?

Yeah I think so.

By the way, could you email me your email address? it would be more convenient talk in my native language. XD

+1 😺

@rhyzx Thank you for posting your issues in English! :smile:

@posva wel ;)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eu81273 picture eu81273  ·  40Comments

yyx990803 picture yyx990803  ·  36Comments

okjesse picture okjesse  ·  49Comments

wenLiangcan picture wenLiangcan  ·  39Comments

Akryum picture Akryum  ·  34Comments