Skip to content

Commit b81ec50

Browse files
authored
feat: allow setting a name for the form (#4933)
* feat: allow setting a name for the form Resolves #4930 * chore: default the name to `Form`
1 parent abf2af1 commit b81ec50

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

packages/vee-validate/src/Form.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ const FormImpl = /** #__PURE__ */ defineComponent({
7575
type: Boolean,
7676
default: false,
7777
},
78+
name: {
79+
type: String,
80+
default: 'Form',
81+
},
7882
},
7983
setup(props, ctx) {
8084
const validationSchema = toRef(props, 'validationSchema');
@@ -108,6 +112,7 @@ const FormImpl = /** #__PURE__ */ defineComponent({
108112
initialTouched: props.initialTouched,
109113
validateOnMount: props.validateOnMount,
110114
keepValuesOnUnmount: keepValues,
115+
name: props.name,
111116
});
112117

113118
const submitForm = handleSubmit((_, { evt }) => {

packages/vee-validate/src/devtools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ function mapFormForDevtoolsInspector(form: PrivateFormContext): CustomInspectorN
254254

255255
return {
256256
id: encodeNodeId(form),
257-
label: 'Form',
257+
label: form.name,
258258
children,
259259
tags: [
260260
{

packages/vee-validate/src/types/forms.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ export interface PrivateFormContext<
323323
TValues extends GenericObject = GenericObject,
324324
TOutput extends GenericObject = TValues,
325325
> extends FormActions<TValues> {
326+
name: string;
326327
formId: number;
327328
values: TValues;
328329
initialValues: Ref<Partial<TValues>>;

packages/vee-validate/src/useForm.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export interface FormOptions<
9292
initialTouched?: FlattenAndSetPathsType<TValues, boolean>;
9393
validateOnMount?: boolean;
9494
keepValuesOnUnmount?: MaybeRef<boolean>;
95+
name?: string;
9596
}
9697

9798
let FORM_COUNTER = 0;
@@ -117,6 +118,7 @@ export function useForm<
117118
| TypedSchema<TValues, TOutput>,
118119
>(opts?: FormOptions<TValues, TOutput, TSchema>): FormContext<TValues, TOutput> {
119120
const formId = FORM_COUNTER++;
121+
const name = opts?.name || 'Form';
120122

121123
// Prevents fields from double resetting their values, which causes checkboxes to toggle their initial value
122124
let FIELD_ID_COUNTER = 0;
@@ -638,6 +640,7 @@ export function useForm<
638640
}
639641

640642
const formCtx: PrivateFormContext<TValues, TOutput> = {
643+
name,
641644
formId,
642645
values: formValues,
643646
controlledValues,

0 commit comments

Comments
 (0)