shadcn-zod-formkit 1.17.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.cjs CHANGED
@@ -5620,10 +5620,11 @@ var DynamicForm = ({
5620
5620
  readOnly = false,
5621
5621
  record = {},
5622
5622
  onSubmit,
5623
+ onClick,
5623
5624
  extraValidations,
5624
5625
  children,
5625
5626
  childrenHeader,
5626
- showIcon = true,
5627
+ showIcon = false,
5627
5628
  showFormHeader = true,
5628
5629
  withErrorsAlert = true,
5629
5630
  errorAlertPosition = "up",
@@ -5644,24 +5645,25 @@ var DynamicForm = ({
5644
5645
  }, [initialValues, form]);
5645
5646
  const handleSubmit = (data) => {
5646
5647
  if (readOnly) return;
5647
- try {
5648
- startTransition(async () => {
5649
- const resp = { data, form };
5650
- onSubmit?.(resp);
5651
- });
5652
- } catch (error) {
5653
- console.error("Ocurri\xF3 un error al enviar el formulario.", error);
5654
- }
5648
+ startTransition(() => {
5649
+ const resp = { data, form };
5650
+ onSubmit?.(resp);
5651
+ });
5652
+ };
5653
+ const handleClick = async () => {
5654
+ if (!onClick) return;
5655
+ const isValid2 = await form.trigger();
5656
+ if (!isValid2) return;
5657
+ const data = form.getValues();
5658
+ const resp = { data, form };
5659
+ onClick(resp);
5655
5660
  };
5656
5661
  const formContent = /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
5657
5662
  showFormHeader && /* @__PURE__ */ jsxRuntime.jsxs(CardTitle, { className: "flex flex-row items-center gap-2 p-2 border-b", children: [
5658
5663
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-row items-center gap-2 w-full", children: [
5659
5664
  showIcon && /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Pencil, { className: "h-5 w-5" }),
5660
5665
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
5661
- /* @__PURE__ */ jsxRuntime.jsxs(CardTitle, { className: "text-xl", children: [
5662
- formTitle,
5663
- " "
5664
- ] }),
5666
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xl", children: formTitle }),
5665
5667
  formSubTitle && /* @__PURE__ */ jsxRuntime.jsx(CardDescription, { children: formSubTitle })
5666
5668
  ] })
5667
5669
  ] }),
@@ -5678,13 +5680,23 @@ var DynamicForm = ({
5678
5680
  /* @__PURE__ */ jsxRuntime.jsx(FormFieldsGrid, { fields, form, readOnly }),
5679
5681
  children && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-row items-center gap-2 w-full h-full", children })
5680
5682
  ] }),
5681
- !readOnly && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-row gap-2 justify-end items-end", children: /* @__PURE__ */ jsxRuntime.jsx(Button, { type: "submit", size: "lg", className: submitBtnClass, disabled: isPending, children: isPending ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5682
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "h-4 w-4 mr-2 animate-spin" }),
5683
- "Guardando..."
5684
- ] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5685
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Save, { className: "h-4 w-4 mr-2" }),
5686
- submitBtnLabel
5687
- ] }) }) })
5683
+ !readOnly && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-row gap-2 justify-end items-end", children: /* @__PURE__ */ jsxRuntime.jsx(
5684
+ Button,
5685
+ {
5686
+ type: onClick ? "button" : "submit",
5687
+ size: "lg",
5688
+ className: submitBtnClass,
5689
+ disabled: isPending,
5690
+ onClick: onClick ? handleClick : void 0,
5691
+ children: isPending ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5692
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "h-4 w-4 mr-2 animate-spin" }),
5693
+ "Guardando..."
5694
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5695
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Save, { className: "h-4 w-4 mr-2" }),
5696
+ submitBtnLabel
5697
+ ] })
5698
+ }
5699
+ ) })
5688
5700
  ]
5689
5701
  }
5690
5702
  ) }),