@@ -53,6 +53,10 @@ export function useForm<TValues extends Record<string, any> = Record<string, any
5353) : FormContext < TValues > {
5454 const formId = FORM_COUNTER ++ ;
5555
56+ // Prevents fields from double resetting their values, which causes checkboxes to toggle their initial value
57+ // TODO: This won't be needed if we centralize all the state inside the `form` for form inputs
58+ let RESET_LOCK = false ;
59+
5660 // A lookup containing fields or field groups
5761 const fieldsByPath : Ref < FieldPathLookup < TValues > > = ref ( { } as any ) ;
5862
@@ -210,8 +214,8 @@ export function useForm<TValues extends Record<string, any> = Record<string, any
210214 return ;
211215 }
212216
213- // Multiple checkboxes, and only one of them got updated
214217 if ( isFieldGroup ( fieldInstance ) && fieldInstance [ 0 ] ?. type === 'checkbox' && ! Array . isArray ( value ) ) {
218+ // Multiple checkboxes, and only one of them got updated
215219 const newValue = deepCopy (
216220 resolveNextCheckboxValue ( getFromPath ( formValues , field as string ) || [ ] , value , undefined )
217221 ) ;
@@ -222,7 +226,7 @@ export function useForm<TValues extends Record<string, any> = Record<string, any
222226
223227 let newValue = value ;
224228 // Single Checkbox: toggles the field value unless the field is being reset then force it
225- if ( ! isFieldGroup ( fieldInstance ) && fieldInstance . type === 'checkbox' && ! force ) {
229+ if ( ! isFieldGroup ( fieldInstance ) && fieldInstance . type === 'checkbox' && ! force && ! RESET_LOCK ) {
226230 newValue = deepCopy (
227231 resolveNextCheckboxValue < TValues [ T ] > (
228232 getFromPath < TValues [ T ] > ( formValues , field as string ) as TValues [ T ] ,
@@ -277,6 +281,7 @@ export function useForm<TValues extends Record<string, any> = Record<string, any
277281 * Resets all fields
278282 */
279283 function resetForm ( state ?: Partial < FormState < TValues > > ) {
284+ RESET_LOCK = true ;
280285 // set initial values if provided
281286 if ( state ?. values ) {
282287 setInitialValues ( state . values ) ;
@@ -293,6 +298,7 @@ export function useForm<TValues extends Record<string, any> = Record<string, any
293298 return ;
294299 }
295300
301+ // avoid resetting the field values, because they should've been reset already.
296302 applyFieldMutation ( field , f => f . resetField ( ) ) ;
297303 } ) ;
298304
@@ -302,6 +308,9 @@ export function useForm<TValues extends Record<string, any> = Record<string, any
302308
303309 setErrors ( state ?. errors || { } ) ;
304310 submitCount . value = state ?. submitCount || 0 ;
311+ nextTick ( ( ) => {
312+ RESET_LOCK = false ;
313+ } ) ;
305314 }
306315
307316 function insertFieldAtPath ( field : PrivateFieldContext , path : string ) {
0 commit comments