Skip to content

feat: allow setting a name for the form #4933

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/vee-validate/src/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ const FormImpl = /** #__PURE__ */ defineComponent({
type: Boolean,
default: false,
},
name: {
type: String,
default: 'Form',
},
},
setup(props, ctx) {
const validationSchema = toRef(props, 'validationSchema');
Expand Down Expand Up @@ -108,6 +112,7 @@ const FormImpl = /** #__PURE__ */ defineComponent({
initialTouched: props.initialTouched,
validateOnMount: props.validateOnMount,
keepValuesOnUnmount: keepValues,
name: props.name,
});

const submitForm = handleSubmit((_, { evt }) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/vee-validate/src/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ function mapFormForDevtoolsInspector(form: PrivateFormContext): CustomInspectorN

return {
id: encodeNodeId(form),
label: 'Form',
label: form.name,
children,
tags: [
{
Expand Down
1 change: 1 addition & 0 deletions packages/vee-validate/src/types/forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ export interface PrivateFormContext<
TValues extends GenericObject = GenericObject,
TOutput extends GenericObject = TValues,
> extends FormActions<TValues> {
name: string;
formId: number;
values: TValues;
initialValues: Ref<Partial<TValues>>;
Expand Down
3 changes: 3 additions & 0 deletions packages/vee-validate/src/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export interface FormOptions<
initialTouched?: FlattenAndSetPathsType<TValues, boolean>;
validateOnMount?: boolean;
keepValuesOnUnmount?: MaybeRef<boolean>;
name?: string;
}

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

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

const formCtx: PrivateFormContext<TValues, TOutput> = {
name,
formId,
values: formValues,
controlledValues,
Expand Down