@@ -1207,6 +1207,57 @@ describe('<Form />', () => {
12071207 expect ( values . textContent ) . toBe ( [ 'Coke' , '' ] . toString ( ) ) ;
12081208 } ) ;
12091209
1210+ test ( 'checkboxes with object values' , async ( ) => {
1211+ const wrapper = mountWithHoc ( {
1212+ setup ( ) {
1213+ const schema = yup . object ( {
1214+ drink : yup . array ( ) . required ( ) . min ( 1 ) ,
1215+ } ) ;
1216+
1217+ return {
1218+ schema,
1219+ } ;
1220+ } ,
1221+ template : `
1222+ <VForm :validation-schema="schema" v-slot="{ errors, values }">
1223+ <Field name="drink" as="input" type="checkbox" :value="{ id: '' }" /> Coffee
1224+ <Field name="drink" as="input" type="checkbox" :value="{ id: 'tea' }" /> Tea
1225+ <Field name="drink" as="input" type="checkbox" :value="{ id: 'coke' }" /> Coke
1226+
1227+ <span id="err">{{ errors.drink }}</span>
1228+ <span id="values">{{ JSON.stringify(values.drink) }}</span>
1229+
1230+ <button>Submit</button>
1231+ </VForm>
1232+ ` ,
1233+ } ) ;
1234+
1235+ const err = wrapper . $el . querySelector ( '#err' ) ;
1236+ const values = wrapper . $el . querySelector ( '#values' ) ;
1237+ const inputs = wrapper . $el . querySelectorAll ( 'input' ) ;
1238+
1239+ wrapper . $el . querySelector ( 'button' ) . click ( ) ;
1240+ await flushPromises ( ) ;
1241+ expect ( err . textContent ) . toBe ( 'drink is a required field' ) ;
1242+ setChecked ( inputs [ 2 ] ) ;
1243+ await flushPromises ( ) ;
1244+ expect ( err . textContent ) . toBe ( '' ) ;
1245+
1246+ setChecked ( inputs [ 0 ] ) ;
1247+ await flushPromises ( ) ;
1248+ expect ( err . textContent ) . toBe ( '' ) ;
1249+
1250+ setChecked ( inputs [ 1 ] ) ;
1251+ await flushPromises ( ) ;
1252+ expect ( err . textContent ) . toBe ( '' ) ;
1253+
1254+ expect ( values . textContent ) . toBe ( JSON . stringify ( [ { id : 'coke' } , { id : '' } , { id : 'tea' } ] ) ) ;
1255+
1256+ setChecked ( inputs [ 1 ] , false ) ;
1257+ await flushPromises ( ) ;
1258+ expect ( values . textContent ) . toBe ( JSON . stringify ( [ { id : 'coke' } , { id : '' } ] ) ) ;
1259+ } ) ;
1260+
12101261 test ( 'checkboxes v-model value syncing' , async ( ) => {
12111262 const drinks = ref < string [ ] > ( [ ] ) ;
12121263 const wrapper = mountWithHoc ( {
0 commit comments