File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed
src/platforms/web/compiler/directives
test/unit/features/directives Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -93,7 +93,7 @@ function genCheckboxModel (
9393 'if(Array.isArray($$a)){' +
9494 `var $$v=${ number ? '_n(' + valueBinding + ')' : valueBinding } ,` +
9595 '$$i=_i($$a,$$v);' +
96- `if($$c ){$$i<0&&(${ value } =$$a.concat($$v))}` +
96+ `if($$el.checked ){$$i<0&&(${ value } =$$a.concat($$v))}` +
9797 `else{$$i>-1&&(${ value } =$$a.slice(0,$$i).concat($$a.slice($$i+1)))}` +
9898 `}else{${ genAssignmentCode ( value , '$$c' ) } }` ,
9999 null , true
Original file line number Diff line number Diff line change @@ -77,6 +77,34 @@ describe('Directive v-model checkbox', () => {
7777 } ) . then ( done )
7878 } )
7979
80+ it ( 'bind to Array value ignores false-value' , done => {
81+ const vm = new Vue ( {
82+ data : {
83+ test : [ '1' ]
84+ } ,
85+ template : `
86+ <div>
87+ <input type="checkbox" v-model="test" value="1" :false-value="true">
88+ <input type="checkbox" v-model="test" value="2" :false-value="true">
89+ </div>
90+ `
91+ } ) . $mount ( )
92+ document . body . appendChild ( vm . $el )
93+ expect ( vm . $el . children [ 0 ] . checked ) . toBe ( true )
94+ expect ( vm . $el . children [ 1 ] . checked ) . toBe ( false )
95+ vm . $el . children [ 0 ] . click ( )
96+ expect ( vm . test . length ) . toBe ( 0 )
97+ vm . $el . children [ 1 ] . click ( )
98+ expect ( vm . test ) . toEqual ( [ '2' ] )
99+ vm . $el . children [ 0 ] . click ( )
100+ expect ( vm . test ) . toEqual ( [ '2' , '1' ] )
101+ vm . test = [ '1' ]
102+ waitForUpdate ( ( ) => {
103+ expect ( vm . $el . children [ 0 ] . checked ) . toBe ( true )
104+ expect ( vm . $el . children [ 1 ] . checked ) . toBe ( false )
105+ } ) . then ( done )
106+ } )
107+
80108 it ( 'bind to Array value with value bindings' , done => {
81109 const vm = new Vue ( {
82110 data : {
You can’t perform that action at this time.
0 commit comments