@formisch/qwik 0.8.0 → 0.9.1

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.
package/README.md CHANGED
@@ -33,7 +33,7 @@ export default component$(() => {
33
33
  });
34
34
 
35
35
  return (
36
- <Form of={loginForm} onSubmit$={(output) => console.log(output)}>
36
+ <Form of={loginForm} onSubmit$={(output, event) => console.log(output)}>
37
37
  <Field
38
38
  of={loginForm}
39
39
  path={['email']}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as v from "valibot";
2
2
  import { JSXOutput, NoSerialize, PropsOf, QRL, ReadonlySignal } from "@qwik.dev/core";
3
- import * as _qwik_dev_core_internal3 from "@qwik.dev/core/internal";
3
+ import * as _qwik_dev_core_internal1 from "@qwik.dev/core/internal";
4
4
 
5
5
  //#region ../../packages/core/dist/index.qwik.d.ts
6
6
 
@@ -227,7 +227,11 @@ type ValidationMode = "initial" | "touch" | "input" | "change" | "blur" | "submi
227
227
  /**
228
228
  * Submit handler type.
229
229
  */
230
- type SubmitHandler<TSchema extends Schema> = (output: v.InferOutput<TSchema>, event: SubmitEvent) => MaybePromise<unknown>;
230
+ type SubmitHandler<TSchema extends Schema> = (output: v.InferOutput<TSchema>) => MaybePromise<unknown>;
231
+ /**
232
+ * Submit event handler type.
233
+ */
234
+ type SubmitEventHandler<TSchema extends Schema> = (output: v.InferOutput<TSchema>, event: SubmitEvent) => MaybePromise<unknown>;
231
235
  //#endregion
232
236
  //#region src/types/form.qwik.d.ts
233
237
  /**
@@ -483,6 +487,17 @@ declare function getInput<TSchema extends Schema, TFieldPath extends RequiredPat
483
487
  //#endregion
484
488
  //#region src/handleSubmit/handleSubmit.d.ts
485
489
  /**
490
+ * Creates a submit event handler for the form that validates the form input,
491
+ * and calls the provided handler if validation succeeds. This is designed to
492
+ * be used with the form's onsubmit event.
493
+ *
494
+ * @param form The form store to handle submission for.
495
+ * @param handler The submit handler function called with validated output if validation succeeds.
496
+ *
497
+ * @returns A submit event handler function to attach to the form element.
498
+ */
499
+ declare function handleSubmit<TSchema extends Schema>(form: BaseFormStore<TSchema>, handler: SubmitHandler<TSchema>): () => Promise<void>;
500
+ /**
486
501
  * Creates a submit event handler for the form that prevents default browser
487
502
  * submission, validates the form input, and calls the provided handler if
488
503
  * validation succeeds. This is designed to be used with the form's onsubmit event.
@@ -492,7 +507,7 @@ declare function getInput<TSchema extends Schema, TFieldPath extends RequiredPat
492
507
  *
493
508
  * @returns A submit event handler function to attach to the form element.
494
509
  */
495
- declare function handleSubmit<TSchema extends Schema>(form: BaseFormStore<TSchema>, handler: SubmitHandler<TSchema>): (event: SubmitEvent) => Promise<void>;
510
+ declare function handleSubmit<TSchema extends Schema>(form: BaseFormStore<TSchema>, handler: SubmitEventHandler<TSchema>): (event: SubmitEvent) => Promise<void>;
496
511
  //#endregion
497
512
  //#region src/insert/insert.d.ts
498
513
  /**
@@ -970,7 +985,7 @@ interface FieldProps<TSchema extends Schema = Schema, TFieldPath extends Require
970
985
  *
971
986
  * @returns The UI of the field to be rendered.
972
987
  */
973
- declare const Field: <TSchema extends Schema, TFieldPath extends RequiredPath>(props: _qwik_dev_core_internal3.PublicProps<FieldProps<TSchema, TFieldPath>>, key: string | null, flags: number, dev?: _qwik_dev_core_internal3.DevJSX) => JSXOutput;
988
+ declare const Field: <TSchema extends Schema, TFieldPath extends RequiredPath>(props: _qwik_dev_core_internal1.PublicProps<FieldProps<TSchema, TFieldPath>>, key: string | null, flags: number, dev?: _qwik_dev_core_internal1.DevJSX) => JSXOutput;
974
989
  //#endregion
975
990
  //#region src/components/FieldArray/FieldArray.d.ts
976
991
  /**
@@ -998,7 +1013,7 @@ interface FieldArrayProps<TSchema extends Schema = Schema, TFieldArrayPath exten
998
1013
  *
999
1014
  * @returns The UI of the field array to be rendered.
1000
1015
  */
1001
- declare const FieldArray: <TSchema extends Schema, TFieldArrayPath extends RequiredPath>(props: _qwik_dev_core_internal3.PublicProps<FieldArrayProps<TSchema, TFieldArrayPath>>, key: string | null, flags: number, dev?: _qwik_dev_core_internal3.DevJSX) => JSXOutput;
1016
+ declare const FieldArray: <TSchema extends Schema, TFieldArrayPath extends RequiredPath>(props: _qwik_dev_core_internal1.PublicProps<FieldArrayProps<TSchema, TFieldArrayPath>>, key: string | null, flags: number, dev?: _qwik_dev_core_internal1.DevJSX) => JSXOutput;
1002
1017
  //#endregion
1003
1018
  //#region src/components/Form/Form.d.ts
1004
1019
  /**
@@ -1012,7 +1027,7 @@ type FormProps<TSchema extends Schema = Schema> = Omit<PropsOf<'form'>, 'onSubmi
1012
1027
  /**
1013
1028
  * The submit handler called when the form is submitted and validation succeeds.
1014
1029
  */
1015
- readonly onSubmit$: QRL<SubmitHandler<TSchema>>;
1030
+ readonly onSubmit$: QRL<SubmitHandler<TSchema>> | QRL<SubmitEventHandler<TSchema>>;
1016
1031
  };
1017
1032
  /**
1018
1033
  * Form component that manages form submission and applies internal state.
@@ -1020,7 +1035,7 @@ type FormProps<TSchema extends Schema = Schema> = Omit<PropsOf<'form'>, 'onSubmi
1020
1035
  *
1021
1036
  * @returns The a native form element.
1022
1037
  */
1023
- declare const Form: <TSchema extends Schema>(props: _qwik_dev_core_internal3.PublicProps<FormProps<TSchema>>, key: string | null, flags: number, dev?: _qwik_dev_core_internal3.DevJSX) => JSXOutput;
1038
+ declare const Form: <TSchema extends Schema>(props: _qwik_dev_core_internal1.PublicProps<FormProps<TSchema>>, key: string | null, flags: number, dev?: _qwik_dev_core_internal1.DevJSX) => JSXOutput;
1024
1039
  //#endregion
1025
1040
  //#region src/hooks/useField/useField.d.ts
1026
1041
  /**
@@ -1080,4 +1095,4 @@ declare function useFormQrl<TSchema extends Schema>(configQrl: QRL<FormConfig<TS
1080
1095
  */
1081
1096
  declare const useForm$: <TSchema extends Schema>(qrl: FormConfig<TSchema>) => FormStore<TSchema>;
1082
1097
  //#endregion
1083
- export { type DeepPartial, Field, FieldArray, FieldArrayProps, FieldArrayStore, type FieldElement, FieldElementProps, FieldProps, FieldStore, FocusFieldConfig, Form, type FormConfig, FormProps, FormStore, GetFieldErrorsConfig, GetFieldInputConfig, GetFormErrorsConfig, GetFormInputConfig, InsertConfig, MoveConfig, type PartialValues, type PathValue, RemoveConfig, ReplaceConfig, type RequiredPath, ResetFieldConfig, ResetFormConfig, type Schema, SetFieldErrorsConfig, SetFieldInputConfig, SetFormErrorsConfig, SetFormInputConfig, type SubmitHandler, SwapConfig, UseFieldArrayConfig, UseFieldConfig, type ValidArrayPath, type ValidPath, ValidateFormConfig, type ValidationMode, focus, getAllErrors, getErrors, getInput, handleSubmit, insert, move, remove, replace, reset, setErrors, setInput, submit, swap, useField, useFieldArray, useForm$, useFormQrl, validate };
1098
+ export { type DeepPartial, Field, FieldArray, FieldArrayProps, FieldArrayStore, type FieldElement, FieldElementProps, FieldProps, FieldStore, FocusFieldConfig, Form, type FormConfig, FormProps, FormStore, GetFieldErrorsConfig, GetFieldInputConfig, GetFormErrorsConfig, GetFormInputConfig, InsertConfig, MoveConfig, type PartialValues, type PathValue, RemoveConfig, ReplaceConfig, type RequiredPath, ResetFieldConfig, ResetFormConfig, type Schema, SetFieldErrorsConfig, SetFieldInputConfig, SetFormErrorsConfig, SetFormInputConfig, type SubmitEventHandler, type SubmitHandler, SwapConfig, UseFieldArrayConfig, UseFieldConfig, type ValidArrayPath, type ValidPath, ValidateFormConfig, type ValidationMode, focus, getAllErrors, getErrors, getInput, handleSubmit, insert, move, remove, replace, reset, setErrors, setInput, submit, swap, useField, useFieldArray, useForm$, useFormQrl, validate };
@@ -585,7 +585,7 @@ function getInput(form, config) {
585
585
  /* @__NO_SIDE_EFFECTS__ */
586
586
  function handleSubmit(form, handler) {
587
587
  return async (event) => {
588
- event.preventDefault();
588
+ event?.preventDefault();
589
589
  const internalFormStore = form[INTERNAL];
590
590
  internalFormStore.isSubmitted.value = true;
591
591
  internalFormStore.isSubmitting.value = true;
@@ -977,7 +977,7 @@ const Form = component$(({ of, onSubmit$,...other }) => {
977
977
  ref: (element) => {
978
978
  of[INTERNAL].element = element;
979
979
  },
980
- onSubmit$: (event) => handleSubmit(of, onSubmit$)(event),
980
+ onSubmit$: handleSubmit(of, onSubmit$),
981
981
  children: /* @__PURE__ */ jsx(Slot, {})
982
982
  });
983
983
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@formisch/qwik",
3
3
  "description": "The modular and type-safe form library for Qwik",
4
- "version": "0.8.0",
4
+ "version": "0.9.1",
5
5
  "license": "MIT",
6
6
  "author": "Fabian Hiller",
7
7
  "homepage": "https://formisch.dev",
@@ -47,9 +47,9 @@
47
47
  "valibot": "^1.2.0",
48
48
  "vite": "7.0.4",
49
49
  "vite-tsconfig-paths": "^5.1.4",
50
- "@formisch/core": "0.5.0",
51
50
  "@formisch/eslint-config": "0.1.0",
52
- "@formisch/methods": "0.6.0"
51
+ "@formisch/methods": "0.7.0",
52
+ "@formisch/core": "0.6.0"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "@qwik.dev/core": ">=2",