File tree Expand file tree Collapse file tree 3 files changed +57
-1
lines changed
test/unit/modules/vdom/patch Expand file tree Collapse file tree 3 files changed +57
-1
lines changed Original file line number Diff line number Diff line change 99// in some cases, the event used has to be determined at runtime
1010// so we used some reserved tokens during compile.
1111export const RANGE_TOKEN = '__r'
12+ export const CHECKBOX_RADIO_TOKEN = '__c'
1213
1314export default function model (
1415 el : ASTElement ,
Original file line number Diff line number Diff line change 33import { isDef , isUndef } from 'shared/util'
44import { updateListeners } from 'core/vdom/helpers/index'
55import { isIE , supportsPassive } from 'core/util/env'
6- import { RANGE_TOKEN } from 'web/compiler/directives/model'
6+ import { RANGE_TOKEN , CHECKBOX_RADIO_TOKEN } from 'web/compiler/directives/model'
77
88// normalize v-model event tokens that can only be determined at runtime.
99// it's important to place the event as the first in the array because
@@ -17,6 +17,13 @@ function normalizeEvents (on) {
1717 on [ event ] = [ ] . concat ( on [ RANGE_TOKEN ] , on [ event ] || [ ] )
1818 delete on [ RANGE_TOKEN ]
1919 }
20+ // This was originally intended to fix #4521 but no longer necessary
21+ // after 2.5. Keeping it for backwards compat with generated code from < 2.4
22+ /* istanbul ignore if */
23+ if ( isDef ( on [ CHECKBOX_RADIO_TOKEN ] ) ) {
24+ on . change = [ ] . concat ( on [ CHECKBOX_RADIO_TOKEN ] , on . change || [ ] )
25+ delete on [ CHECKBOX_RADIO_TOKEN ]
26+ }
2027}
2128
2229let target : HTMLElement
Original file line number Diff line number Diff line change @@ -198,4 +198,52 @@ describe('vdom patch: edge cases', () => {
198198 } ) . $mount ( )
199199 expect ( vm . $el . textContent ) . toBe ( '' )
200200 } )
201+
202+ // #6803
203+ it ( 'backwards compat with checkbox code generated before 2.4' , ( ) => {
204+ const spy = jasmine . createSpy ( )
205+ const vm = new Vue ( {
206+ data : {
207+ label : 'foobar' ,
208+ name : 'foobar'
209+ } ,
210+ computed : {
211+ value : {
212+ get ( ) {
213+ return 1
214+ } ,
215+ set : spy
216+ }
217+ } ,
218+ render ( h ) {
219+ const _vm = this
220+ return h ( 'div' , { } ,
221+ [ h ( 'input' , {
222+ directives : [ {
223+ name : 'model' ,
224+ rawName : 'v-model' ,
225+ value : ( _vm . value ) ,
226+ expression : 'value'
227+ } ] ,
228+ attrs : {
229+ 'type' : 'radio' ,
230+ 'name' : _vm . name
231+ } ,
232+ domProps : {
233+ 'value' : _vm . label ,
234+ 'checked' : _vm . _q ( _vm . value , _vm . label )
235+ } ,
236+ on : {
237+ '__c' : function ( $event ) {
238+ _vm . value = _vm . label
239+ }
240+ }
241+ } ) ] )
242+ }
243+ } ) . $mount ( )
244+
245+ document . body . appendChild ( vm . $el )
246+ vm . $el . children [ 0 ] . click ( )
247+ expect ( spy ) . toHaveBeenCalled ( )
248+ } )
201249} )
You can’t perform that action at this time.
0 commit comments