shadcn-zod-formkit 1.18.0 → 1.18.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/dist/index.d.mts CHANGED
@@ -203,7 +203,7 @@ interface Props$4<T extends Record<string, any>> {
203
203
  fields: Array<FieldProps<T> | FieldProps<T>[]>;
204
204
  record?: Partial<T>;
205
205
  onSubmit?: (resp: FormResp<T>) => void;
206
- onClick?: () => void;
206
+ onClick?: (resp: FormResp<T>) => void;
207
207
  extraValidations?: ((schema: ZodObject<any>) => ZodObject<any>)[];
208
208
  withErrorsAlert?: boolean;
209
209
  errorAlertPosition?: alertPositionType;
package/dist/index.d.ts CHANGED
@@ -203,7 +203,7 @@ interface Props$4<T extends Record<string, any>> {
203
203
  fields: Array<FieldProps<T> | FieldProps<T>[]>;
204
204
  record?: Partial<T>;
205
205
  onSubmit?: (resp: FormResp<T>) => void;
206
- onClick?: () => void;
206
+ onClick?: (resp: FormResp<T>) => void;
207
207
  extraValidations?: ((schema: ZodObject<any>) => ZodObject<any>)[];
208
208
  withErrorsAlert?: boolean;
209
209
  errorAlertPosition?: alertPositionType;
package/dist/index.mjs CHANGED
@@ -5591,7 +5591,6 @@ var DynamicForm = ({
5591
5591
  withErrorsAlert = true,
5592
5592
  errorAlertPosition = "up",
5593
5593
  withCard = false,
5594
- // btnType = 'submit',
5595
5594
  submitBtnClass = "",
5596
5595
  submitBtnLabel = "Guardar"
5597
5596
  }) => {
@@ -5608,24 +5607,25 @@ var DynamicForm = ({
5608
5607
  }, [initialValues, form]);
5609
5608
  const handleSubmit = (data) => {
5610
5609
  if (readOnly) return;
5611
- try {
5612
- startTransition(async () => {
5613
- const resp = { data, form };
5614
- onSubmit?.(resp);
5615
- });
5616
- } catch (error) {
5617
- console.error("Ocurri\xF3 un error al enviar el formulario.", error);
5618
- }
5610
+ startTransition(() => {
5611
+ const resp = { data, form };
5612
+ onSubmit?.(resp);
5613
+ });
5614
+ };
5615
+ const handleClick = async () => {
5616
+ if (!onClick) return;
5617
+ const isValid2 = await form.trigger();
5618
+ if (!isValid2) return;
5619
+ const data = form.getValues();
5620
+ const resp = { data, form };
5621
+ onClick(resp);
5619
5622
  };
5620
5623
  const formContent = /* @__PURE__ */ jsxs("div", { children: [
5621
5624
  showFormHeader && /* @__PURE__ */ jsxs(CardTitle, { className: "flex flex-row items-center gap-2 p-2 border-b", children: [
5622
5625
  /* @__PURE__ */ jsxs("div", { className: "flex flex-row items-center gap-2 w-full", children: [
5623
5626
  showIcon && /* @__PURE__ */ jsx(Pencil, { className: "h-5 w-5" }),
5624
5627
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
5625
- /* @__PURE__ */ jsxs("div", { className: "text-xl", children: [
5626
- formTitle,
5627
- " "
5628
- ] }),
5628
+ /* @__PURE__ */ jsx("div", { className: "text-xl", children: formTitle }),
5629
5629
  formSubTitle && /* @__PURE__ */ jsx(CardDescription, { children: formSubTitle })
5630
5630
  ] })
5631
5631
  ] }),
@@ -5642,13 +5642,23 @@ var DynamicForm = ({
5642
5642
  /* @__PURE__ */ jsx(FormFieldsGrid, { fields, form, readOnly }),
5643
5643
  children && /* @__PURE__ */ jsx("div", { className: "flex flex-row items-center gap-2 w-full h-full", children })
5644
5644
  ] }),
5645
- !readOnly && /* @__PURE__ */ jsx("div", { className: "flex flex-row gap-2 justify-end items-end", children: /* @__PURE__ */ jsx(Button, { type: onClick ? "button" : "submit", size: "lg", className: submitBtnClass, disabled: isPending, onClick, children: isPending ? /* @__PURE__ */ jsxs(Fragment, { children: [
5646
- /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 mr-2 animate-spin" }),
5647
- "Guardando..."
5648
- ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
5649
- /* @__PURE__ */ jsx(Save, { className: "h-4 w-4 mr-2" }),
5650
- submitBtnLabel
5651
- ] }) }) })
5645
+ !readOnly && /* @__PURE__ */ jsx("div", { className: "flex flex-row gap-2 justify-end items-end", children: /* @__PURE__ */ jsx(
5646
+ Button,
5647
+ {
5648
+ type: onClick ? "button" : "submit",
5649
+ size: "lg",
5650
+ className: submitBtnClass,
5651
+ disabled: isPending,
5652
+ onClick: onClick ? handleClick : void 0,
5653
+ children: isPending ? /* @__PURE__ */ jsxs(Fragment, { children: [
5654
+ /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 mr-2 animate-spin" }),
5655
+ "Guardando..."
5656
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
5657
+ /* @__PURE__ */ jsx(Save, { className: "h-4 w-4 mr-2" }),
5658
+ submitBtnLabel
5659
+ ] })
5660
+ }
5661
+ ) })
5652
5662
  ]
5653
5663
  }
5654
5664
  ) }),