File tree Expand file tree Collapse file tree 4 files changed +33
-15
lines changed Expand file tree Collapse file tree 4 files changed +33
-15
lines changed Original file line number Diff line number Diff line change @@ -232,6 +232,14 @@ function compileNode (node, options) {
232
232
*/
233
233
234
234
function compileElement ( el , options ) {
235
+ // preprocess textareas.
236
+ // textarea treats its text content as the initial value.
237
+ // just bind it as a v-attr directive for value.
238
+ if ( el . tagName === 'TEXTAREA' ) {
239
+ if ( textParser . parse ( el . value ) ) {
240
+ el . setAttribute ( 'value' , el . value )
241
+ }
242
+ }
235
243
var linkFn
236
244
var hasAttrs = el . hasAttributes ( )
237
245
// check terminal directives (repeat & if)
@@ -250,16 +258,6 @@ function compileElement (el, options) {
250
258
if ( ! linkFn && hasAttrs ) {
251
259
linkFn = compileDirectives ( el . attributes , options )
252
260
}
253
- // if the element is a textarea, we need to interpolate
254
- // its content on initial render.
255
- if ( el . tagName === 'TEXTAREA' ) {
256
- var realLinkFn = linkFn
257
- linkFn = function ( vm , el ) {
258
- el . value = vm . $interpolate ( el . value )
259
- if ( realLinkFn ) realLinkFn ( vm , el )
260
- }
261
- linkFn . terminal = true
262
- }
263
261
return linkFn
264
262
}
265
263
Original file line number Diff line number Diff line change @@ -35,7 +35,13 @@ module.exports = {
35
35
} ,
36
36
37
37
setAttr : function ( attr , value ) {
38
- if ( value != null && value !== false ) {
38
+ if ( attr === 'value' && attr in this . el ) {
39
+ if ( ! this . valueRemoved ) {
40
+ this . el . removeAttribute ( attr )
41
+ this . valueRemoved = true
42
+ }
43
+ this . el . value = value
44
+ } else if ( value != null && value !== false ) {
39
45
if ( xlinkRE . test ( attr ) ) {
40
46
this . el . setAttributeNS ( xlinkNS , attr , value )
41
47
} else {
@@ -44,8 +50,5 @@ module.exports = {
44
50
} else {
45
51
this . el . removeAttribute ( attr )
46
52
}
47
- if ( attr === 'value' && 'value' in this . el ) {
48
- this . el . value = value
49
- }
50
53
}
51
54
}
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ if (_.inBrowser) {
30
30
dir . el = document . createElement ( 'input' )
31
31
dir . arg = 'value'
32
32
dir . update ( 'what' )
33
- expect ( dir . el . getAttribute ( 'value' ) ) . toBe ( 'what' )
33
+ expect ( dir . el . hasAttribute ( 'value' ) ) . toBe ( false )
34
34
expect ( dir . el . value ) . toBe ( 'what' )
35
35
} )
36
36
Original file line number Diff line number Diff line change @@ -292,4 +292,21 @@ describe('Misc', function () {
292
292
}
293
293
} )
294
294
295
+ it ( 'handle interpolated textarea' , function ( done ) {
296
+ var el = document . createElement ( 'div' )
297
+ el . innerHTML = '<textarea>hello {{msg}}</textarea>'
298
+ var vm = new Vue ( {
299
+ el : el ,
300
+ data : {
301
+ msg : 'test'
302
+ }
303
+ } )
304
+ expect ( el . innerHTML ) . toBe ( '<textarea>hello test</textarea>' )
305
+ vm . msg = 'world'
306
+ Vue . nextTick ( function ( ) {
307
+ expect ( el . innerHTML ) . toBe ( '<textarea>hello world</textarea>' )
308
+ done ( )
309
+ } )
310
+ } )
311
+
295
312
} )
You can’t perform that action at this time.
0 commit comments