Skip to content

Commit 59c9456

Browse files
committed
v-attr should also set property for checked and selected
1 parent da7ac62 commit 59c9456

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/directives/attr.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// xlink
22
var xlinkNS = 'http://www.w3.org/1999/xlink'
33
var xlinkRE = /^xlink:/
4+
var inputProps = {
5+
value: 1,
6+
checked: 1,
7+
selected: 1
8+
}
49

510
module.exports = {
611

@@ -35,12 +40,12 @@ module.exports = {
3540
},
3641

3742
setAttr: function (attr, value) {
38-
if (attr === 'value' && attr in this.el) {
43+
if (inputProps[attr] && attr in this.el) {
3944
if (!this.valueRemoved) {
4045
this.el.removeAttribute(attr)
4146
this.valueRemoved = true
4247
}
43-
this.el.value = value
48+
this.el[attr] = value
4449
} else if (value != null && value !== false) {
4550
if (xlinkRE.test(attr)) {
4651
this.el.setAttributeNS(xlinkNS, attr, value)

test/unit/specs/directives/attr_spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ if (_.inBrowser) {
3232
dir.update('what')
3333
expect(dir.el.hasAttribute('value')).toBe(false)
3434
expect(dir.el.value).toBe('what')
35+
dir.el = document.createElement('input')
36+
dir.el.type = 'checkbox'
37+
dir.arg = 'checked'
38+
expect(dir.el.checked).toBe(false)
39+
dir.update(true)
40+
expect(dir.el.checked).toBe(true)
3541
})
3642

3743
it('xlink', function () {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy