shadcn-zod-formkit 1.9.2 → 1.10.0
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 +47 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +47 -8
- package/dist/index.mjs.map +1 -1
- package/dist/shadcn-zod-formkit-1.10.0.tgz +0 -0
- package/package.json +1 -1
- package/dist/shadcn-zod-formkit-1.9.2.tgz +0 -0
package/dist/index.cjs
CHANGED
|
@@ -4524,11 +4524,12 @@ var FieldSelect = ({ form, input, isSubmitting }) => {
|
|
|
4524
4524
|
{ value: 3, id: 3, name: "MOCK OPTION - PERMISO 3" },
|
|
4525
4525
|
{ value: 4, id: 4, name: "MOCK OPTION - PERMISO 4" }
|
|
4526
4526
|
];
|
|
4527
|
-
const lista =
|
|
4528
|
-
|
|
4529
|
-
const [value, setValue] = React3.useState(
|
|
4530
|
-
input.value?.toString() ?? ""
|
|
4527
|
+
const [lista, setLista] = React3.useState(
|
|
4528
|
+
input?.listConfig?.list?.every((item) => "name" in item) ? input.listConfig.list : mockInputOptions
|
|
4531
4529
|
);
|
|
4530
|
+
const [loading, setLoading] = React3.useState(false);
|
|
4531
|
+
const [value, setValue] = React3.useState(input.value?.toString() ?? "");
|
|
4532
|
+
const optionValue = input?.listConfig?.optionValue ?? input.optionValue ?? "id";
|
|
4532
4533
|
React3.useEffect(() => {
|
|
4533
4534
|
const currentValue = form.getValues(input.name);
|
|
4534
4535
|
if (!currentValue && input.value) {
|
|
@@ -4536,8 +4537,32 @@ var FieldSelect = ({ form, input, isSubmitting }) => {
|
|
|
4536
4537
|
setValue(input.value.toString());
|
|
4537
4538
|
}
|
|
4538
4539
|
}, [form, input.name, input.value]);
|
|
4540
|
+
React3.useEffect(() => {
|
|
4541
|
+
if (input.dependsOn && input.loadOptions) {
|
|
4542
|
+
const subscription = form.watch(async (values) => {
|
|
4543
|
+
const dependencyValue = values[input.dependsOn];
|
|
4544
|
+
if (dependencyValue) {
|
|
4545
|
+
try {
|
|
4546
|
+
setLoading(true);
|
|
4547
|
+
const newOptions = await input.loadOptions(dependencyValue);
|
|
4548
|
+
setLista(newOptions);
|
|
4549
|
+
} catch (err) {
|
|
4550
|
+
console.error(`Error loading options for ${input.name}:`, err);
|
|
4551
|
+
setLista([]);
|
|
4552
|
+
} finally {
|
|
4553
|
+
setLoading(false);
|
|
4554
|
+
}
|
|
4555
|
+
} else {
|
|
4556
|
+
setLista([]);
|
|
4557
|
+
form.setValue(input.name, "");
|
|
4558
|
+
}
|
|
4559
|
+
});
|
|
4560
|
+
return () => subscription.unsubscribe?.();
|
|
4561
|
+
}
|
|
4562
|
+
}, [form, input.dependsOn, input.loadOptions, input.name]);
|
|
4539
4563
|
const getValue = (item) => {
|
|
4540
|
-
|
|
4564
|
+
const val = optionValue === "name" ? item.name : item.value?.toString?.() ?? item.id?.toString();
|
|
4565
|
+
return val?.toString() ?? "";
|
|
4541
4566
|
};
|
|
4542
4567
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4543
4568
|
FormField,
|
|
@@ -4555,15 +4580,29 @@ var FieldSelect = ({ form, input, isSubmitting }) => {
|
|
|
4555
4580
|
/* @__PURE__ */ jsxRuntime.jsx(FormControl, { children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4556
4581
|
Select,
|
|
4557
4582
|
{
|
|
4558
|
-
disabled: input.disabled || isSubmitting,
|
|
4583
|
+
disabled: input.disabled || isSubmitting || loading,
|
|
4559
4584
|
onValueChange: (val) => {
|
|
4560
4585
|
field.onChange(val);
|
|
4561
4586
|
setValue(val);
|
|
4587
|
+
if (input.listConfig?.onOptionChange) {
|
|
4588
|
+
const selectedItem = lista.find(
|
|
4589
|
+
(item) => getValue(item) === val
|
|
4590
|
+
);
|
|
4591
|
+
input.listConfig.onOptionChange(selectedItem);
|
|
4592
|
+
}
|
|
4562
4593
|
},
|
|
4563
4594
|
value: currentValue || void 0,
|
|
4564
4595
|
children: [
|
|
4565
|
-
/* @__PURE__ */ jsxRuntime.jsx(FormControl, { children: /* @__PURE__ */ jsxRuntime.jsx(SelectTrigger, { className: "w-[60%] bg-black/10 dark:bg-white/25", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4566
|
-
|
|
4596
|
+
/* @__PURE__ */ jsxRuntime.jsx(FormControl, { children: /* @__PURE__ */ jsxRuntime.jsx(SelectTrigger, { className: "w-[60%] bg-black/10 dark:bg-white/25", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4597
|
+
SelectValue,
|
|
4598
|
+
{
|
|
4599
|
+
placeholder: loading ? "Cargando..." : input.placeHolder ?? "Seleccionar"
|
|
4600
|
+
}
|
|
4601
|
+
) }) }),
|
|
4602
|
+
/* @__PURE__ */ jsxRuntime.jsxs(SelectContent, { children: [
|
|
4603
|
+
lista.map((item) => /* @__PURE__ */ jsxRuntime.jsx(SelectItem, { value: getValue(item), children: item.name }, item.id)),
|
|
4604
|
+
lista.length === 0 && !loading && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-2 text-sm text-muted-foreground", children: "No hay opciones disponibles" })
|
|
4605
|
+
] })
|
|
4567
4606
|
]
|
|
4568
4607
|
}
|
|
4569
4608
|
) })
|