@@ -55,15 +55,21 @@ export interface FieldOptions<TValue = unknown> {
5555 validateOnMount ?: boolean ;
5656 bails ?: boolean ;
5757 type ?: InputType ;
58+ /**
59+ * @deprecated Use `checkedValue` instead.
60+ */
5861 valueProp ?: MaybeRef < TValue > ;
5962 checkedValue ?: MaybeRef < TValue > ;
6063 uncheckedValue ?: MaybeRef < TValue > ;
6164 label ?: MaybeRef < string | undefined > ;
6265 controlled ?: boolean ;
6366 standalone ?: boolean ;
6467 keepValueOnUnmount ?: MaybeRef < boolean | undefined > ;
68+ /**
69+ * @deprecated Pass the model prop name to `syncVModel` instead.
70+ */
6571 modelPropName ?: string ;
66- syncVModel ?: boolean ;
72+ syncVModel ?: boolean | string ;
6773 form ?: FormContext ;
6874}
6975
@@ -107,7 +113,6 @@ function _useField<TValue = unknown>(
107113 uncheckedValue,
108114 controlled,
109115 keepValueOnUnmount,
110- modelPropName,
111116 syncVModel,
112117 form : controlForm ,
113118 } = normalizeOptions ( opts ) ;
@@ -148,7 +153,7 @@ function _useField<TValue = unknown>(
148153 const errorMessage = computed ( ( ) => errors . value [ 0 ] ) ;
149154
150155 if ( syncVModel ) {
151- useVModel ( { value, prop : modelPropName , handleChange } ) ;
156+ useVModel ( { value, prop : syncVModel , handleChange } ) ;
152157 }
153158
154159 /**
@@ -451,15 +456,15 @@ function normalizeOptions<TValue>(opts: Partial<FieldOptions<TValue>> | undefine
451456 label : undefined ,
452457 validateOnValueUpdate : true ,
453458 keepValueOnUnmount : undefined ,
454- modelPropName : 'modelValue' ,
455459 syncVModel : false ,
456460 controlled : true ,
457461 } ) ;
458462
459- const isVModelSynced = opts ?. syncVModel ?? true ;
463+ const isVModelSynced = ! ! opts ?. syncVModel ;
464+ const modelPropName = typeof opts ?. syncVModel === 'string' ? opts . syncVModel : opts ?. modelPropName || 'modelValue' ;
460465 const initialValue =
461466 isVModelSynced && ! ( 'initialValue' in ( opts || { } ) )
462- ? getCurrentModelValue ( getCurrentInstance ( ) , opts ?. modelPropName || 'modelValue' )
467+ ? getCurrentModelValue ( getCurrentInstance ( ) , modelPropName )
463468 : opts ?. initialValue ;
464469
465470 if ( ! opts ) {
@@ -469,13 +474,15 @@ function normalizeOptions<TValue>(opts: Partial<FieldOptions<TValue>> | undefine
469474 // TODO: Deprecate this in next major release
470475 const checkedValue = 'valueProp' in opts ? opts . valueProp : opts . checkedValue ;
471476 const controlled = 'standalone' in opts ? ! opts . standalone : opts . controlled ;
477+ const syncVModel = opts ?. modelPropName || opts ?. syncVModel || false ;
472478
473479 return {
474480 ...defaults ( ) ,
475481 ...( opts || { } ) ,
476482 initialValue,
477483 controlled : controlled ?? true ,
478484 checkedValue,
485+ syncVModel,
479486 } as FieldOptions < TValue > ;
480487}
481488
@@ -537,22 +544,22 @@ function useFieldWithChecked<TValue = unknown>(
537544}
538545
539546interface ModelOpts < TValue > {
540- prop ? : string ;
547+ prop : string | boolean ;
541548 value : Ref < TValue > ;
542549 handleChange : FieldContext [ 'handleChange' ] ;
543550}
544551
545552function useVModel < TValue = unknown > ( { prop, value, handleChange } : ModelOpts < TValue > ) {
546553 const vm = getCurrentInstance ( ) ;
547554 /* istanbul ignore next */
548- if ( ! vm ) {
555+ if ( ! vm || ! prop ) {
549556 if ( __DEV__ ) {
550557 console . warn ( 'Failed to setup model events because `useField` was not called in setup.' ) ;
551558 }
552559 return ;
553560 }
554561
555- const propName = prop || 'modelValue' ;
562+ const propName = typeof prop === 'string' ? prop : 'modelValue' ;
556563 const emitName = `update:${ propName } ` ;
557564
558565 // Component doesn't have a model prop setup (must be defined on the props)
0 commit comments