Browse Source

v-bind: do not remove input value attributes

Evan You 10 years ago
parent
commit
17833f9c79
2 changed files with 15 additions and 13 deletions
  1. 15 12
      src/directives/public/bind.js
  2. 0 1
      test/unit/specs/directives/public/bind_spec.js

+ 15 - 12
src/directives/public/bind.js

@@ -84,19 +84,7 @@ module.exports = {
     }
     var attr = this.arg
     if (inputProps[attr] && attr in this.el) {
-      if (!this.valueRemoved) {
-        this.el.removeAttribute(attr)
-        this.valueRemoved = true
-      }
       this.el[attr] = value
-    } else if (value != null && value !== false) {
-      if (xlinkRE.test(attr)) {
-        this.el.setAttributeNS(xlinkNS, attr, value)
-      } else {
-        this.el.setAttribute(attr, value)
-      }
-    } else {
-      this.el.removeAttribute(attr)
     }
     // set model props
     var modelProp = modelProps[attr]
@@ -108,5 +96,20 @@ module.exports = {
         model.listener()
       }
     }
+    // do not set value attribute for textarea
+    if (attr === 'value' && this.el.tagName === 'TEXTAREA') {
+      this.el.removeAttribute(attr)
+      return
+    }
+    // update attribute
+    if (value != null && value !== false) {
+      if (xlinkRE.test(attr)) {
+        this.el.setAttributeNS(xlinkNS, attr, value)
+      } else {
+        this.el.setAttribute(attr, value)
+      }
+    } else {
+      this.el.removeAttribute(attr)
+    }
   }
 }

+ 0 - 1
test/unit/specs/directives/public/bind_spec.js

@@ -29,7 +29,6 @@ if (_.inBrowser) {
       dir.el = document.createElement('input')
       dir.arg = 'value'
       dir.update('what')
-      expect(dir.el.hasAttribute('value')).toBe(false)
       expect(dir.el.value).toBe('what')
       dir.el = document.createElement('input')
       dir.el.type = 'checkbox'