maz-ui 4.3.4-beta.3 → 4.3.4-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -47,6 +47,11 @@ export interface FormValidatorOptions<Model extends BaseFormPayload = BaseFormPa
47
47
  * @default `main-form-validator`
48
48
  */
49
49
  identifier?: string | symbol;
50
+ /**
51
+ * Reset the form on submit success - you must use handleSubmit to handle the form submission
52
+ * @default true
53
+ */
54
+ resetOnSuccess?: boolean;
50
55
  }
51
56
  export type StrictOptions<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>>> = Required<FormValidatorOptions<Model, ModelKey>>;
52
57
  export interface FormContext<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>>> {
@@ -18,6 +18,9 @@ export declare function useFormValidator<TSchema extends MaybeRefOrGetter<FormSc
18
18
  fieldsStates: Ref<FieldsStates<InferSchemaFormValidator<TSchema>, ExtractModelKey<FormSchema<InferSchemaFormValidator<TSchema>>>>, FieldsStates<InferSchemaFormValidator<TSchema>, ExtractModelKey<FormSchema<InferSchemaFormValidator<TSchema>>>>>;
19
19
  validateForm: (setErrors?: boolean) => Promise<void[]>;
20
20
  scrollToError: typeof scrollToError;
21
- handleSubmit: <Func extends (model: InferOutputSchemaFormValidator<TSchema>) => Promise<Awaited<ReturnType<Func>>> | ReturnType<Func>>(successCallback: Func, enableScrollOrSelector?: FormValidatorOptions["scrollToError"]) => (event?: Event) => Promise<ReturnType<Func> | undefined>;
21
+ resetForm: () => void;
22
+ handleSubmit: <Func extends (model: InferOutputSchemaFormValidator<TSchema>) => Promise<Awaited<ReturnType<Func>>> | ReturnType<Func>>(successCallback: Func, enableScrollOrSelector?: FormValidatorOptions["scrollToError"], options?: {
23
+ resetOnSuccess?: boolean;
24
+ }) => (event?: Event) => Promise<ReturnType<Func> | undefined>;
22
25
  errorMessages: import('vue').ComputedRef<Record<ExtractModelKey<FormSchema<InferSchemaFormValidator<TSchema>>>, string | undefined>>;
23
26
  };
@@ -22,6 +22,7 @@ function useFormValidator({ schema, defaultValues, model, options }) {
22
22
  debouncedFields: null,
23
23
  throttledFields: null,
24
24
  identifier: "main-form-validator",
25
+ resetOnSuccess: !0,
25
26
  ...options
26
27
  }, internalDefaultValues = ref(toValue(defaultValues)), payload = ref({ ...internalDefaultValues.value, ...model?.value }), internalSchema = ref(toValue(schema)), fieldsStates = ref(
27
28
  getFieldsStates({
@@ -102,7 +103,17 @@ function useFormValidator({ schema, defaultValues, model, options }) {
102
103
  { deep: !0 }
103
104
  );
104
105
  }
105
- function handleSubmit(successCallback, enableScrollOrSelector) {
106
+ function resetForm() {
107
+ payloadWatchStop && payloadWatchStop(), isSubmitting.value = !1, isSubmitted.value = !1, payload.value = { ...internalDefaultValues.value }, fieldsStates.value = getFieldsStates({
108
+ schema: internalSchema.value,
109
+ payload: payload.value,
110
+ options: opts
111
+ }), internalValidateForm(!1), setupOptimizedWatch();
112
+ }
113
+ function handleSubmit(successCallback, enableScrollOrSelector, options2) {
114
+ const finalOptions = {
115
+ resetOnSuccess: options2?.resetOnSuccess ?? opts.resetOnSuccess
116
+ };
106
117
  return async (event) => {
107
118
  if (event?.preventDefault(), !isSubmitting.value) {
108
119
  isSubmitted.value = !0, isSubmitting.value = !0;
@@ -110,7 +121,7 @@ function useFormValidator({ schema, defaultValues, model, options }) {
110
121
  await internalValidateForm(!0);
111
122
  const scrollToErrorParam = typeof enableScrollOrSelector == "string" ? enableScrollOrSelector : opts.scrollToError;
112
123
  let response;
113
- return isValid.value ? response = await successCallback(payload.value) : typeof scrollToErrorParam != "boolean" && scrollToError(scrollToErrorParam), isSubmitting.value = !1, response;
124
+ return isValid.value ? (response = await successCallback(payload.value), (finalOptions.resetOnSuccess || options2?.resetOnSuccess) && resetForm()) : typeof scrollToErrorParam != "boolean" && scrollToError(scrollToErrorParam), isSubmitting.value = !1, response;
114
125
  } finally {
115
126
  isSubmitting.value = !1;
116
127
  }
@@ -136,6 +147,7 @@ function useFormValidator({ schema, defaultValues, model, options }) {
136
147
  fieldsStates,
137
148
  validateForm: internalValidateForm,
138
149
  scrollToError,
150
+ resetForm,
139
151
  handleSubmit,
140
152
  errorMessages
141
153
  };
@@ -47,6 +47,11 @@ export interface FormValidatorOptions<Model extends BaseFormPayload = BaseFormPa
47
47
  * @default `main-form-validator`
48
48
  */
49
49
  identifier?: string | symbol;
50
+ /**
51
+ * Reset the form on submit success - you must use handleSubmit to handle the form submission
52
+ * @default true
53
+ */
54
+ resetOnSuccess?: boolean;
50
55
  }
51
56
  export type StrictOptions<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>>> = Required<FormValidatorOptions<Model, ModelKey>>;
52
57
  export interface FormContext<Model extends BaseFormPayload, ModelKey extends ExtractModelKey<FormSchema<Model>>> {
@@ -18,6 +18,9 @@ export declare function useFormValidator<TSchema extends MaybeRefOrGetter<FormSc
18
18
  fieldsStates: Ref<FieldsStates<InferSchemaFormValidator<TSchema>, ExtractModelKey<FormSchema<InferSchemaFormValidator<TSchema>>>>, FieldsStates<InferSchemaFormValidator<TSchema>, ExtractModelKey<FormSchema<InferSchemaFormValidator<TSchema>>>>>;
19
19
  validateForm: (setErrors?: boolean) => Promise<void[]>;
20
20
  scrollToError: typeof scrollToError;
21
- handleSubmit: <Func extends (model: InferOutputSchemaFormValidator<TSchema>) => Promise<Awaited<ReturnType<Func>>> | ReturnType<Func>>(successCallback: Func, enableScrollOrSelector?: FormValidatorOptions["scrollToError"]) => (event?: Event) => Promise<ReturnType<Func> | undefined>;
21
+ resetForm: () => void;
22
+ handleSubmit: <Func extends (model: InferOutputSchemaFormValidator<TSchema>) => Promise<Awaited<ReturnType<Func>>> | ReturnType<Func>>(successCallback: Func, enableScrollOrSelector?: FormValidatorOptions["scrollToError"], options?: {
23
+ resetOnSuccess?: boolean;
24
+ }) => (event?: Event) => Promise<ReturnType<Func> | undefined>;
22
25
  errorMessages: import('vue').ComputedRef<Record<ExtractModelKey<FormSchema<InferSchemaFormValidator<TSchema>>>, string | undefined>>;
23
26
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "maz-ui",
3
3
  "type": "module",
4
- "version": "4.3.4-beta.3",
4
+ "version": "4.3.4-beta.4",
5
5
  "description": "A standalone components library for Vue.Js 3 & Nuxt.Js 3",
6
6
  "author": "Louis Mazel <me@loicmazuel.com>",
7
7
  "license": "MIT",
@@ -178,9 +178,9 @@
178
178
  "libphonenumber-js": "^1.12.33",
179
179
  "valibot": "^1.2.0",
180
180
  "vue-chartjs": "^5.3.3",
181
- "@maz-ui/themes": "4.3.0",
182
- "@maz-ui/icons": "4.3.0",
183
181
  "@maz-ui/cli": "4.3.4-beta.0",
182
+ "@maz-ui/icons": "4.3.0",
183
+ "@maz-ui/themes": "4.3.0",
184
184
  "@maz-ui/utils": "4.3.0",
185
185
  "@maz-ui/translations": "4.3.0"
186
186
  },
@@ -217,8 +217,8 @@
217
217
  "vue": "^3.5.26",
218
218
  "vue-router": "^4.6.4",
219
219
  "vue-tsc": "^3.2.1",
220
- "@maz-ui/node": "4.3.4-beta.0",
221
- "@maz-ui/eslint-config": "4.3.2"
220
+ "@maz-ui/eslint-config": "4.3.2",
221
+ "@maz-ui/node": "4.3.4-beta.0"
222
222
  },
223
223
  "lint-staged": {
224
224
  "*.{js,ts,vue,mjs,mts,cjs,md,yml,json}": "cross-env NODE_ENV=production eslint --fix",