shadcn-zod-formkit 3.0.0 → 3.1.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 CHANGED
@@ -12982,6 +12982,7 @@ var FieldMultiSelect = ({ form, input, isSubmitting }) => {
12982
12982
  if (optionValue === "name") return item[optionValue];
12983
12983
  return item.value ?? item.id;
12984
12984
  };
12985
+ const normalize = (v) => v?.toString();
12985
12986
  const [open, setOpen] = React3.useState(false);
12986
12987
  return /* @__PURE__ */ jsxRuntime.jsx(
12987
12988
  FormField,
@@ -12990,8 +12991,11 @@ var FieldMultiSelect = ({ form, input, isSubmitting }) => {
12990
12991
  name: input.name,
12991
12992
  render: ({ field }) => {
12992
12993
  const selectedValues = Array.isArray(field.value) ? field.value : [];
12993
- const toggleOption = (value) => {
12994
- const newValues = selectedValues.includes(value) ? selectedValues.filter((v) => v !== value) : [...selectedValues, value];
12994
+ const toggleOption = (rawValue) => {
12995
+ const normalized = selectedValues.map((v) => normalize(v));
12996
+ const value = normalize(rawValue);
12997
+ const exists = normalized.includes(value);
12998
+ const newValues = exists ? selectedValues.filter((v) => normalize(v) !== value) : [...selectedValues, rawValue];
12995
12999
  field.onChange(newValues);
12996
13000
  };
12997
13001
  return /* @__PURE__ */ jsxRuntime.jsxs(FormItem, { className: "flex flex-col rounded-lg border p-3 shadow bg-blue-100/20", children: [
@@ -13011,9 +13015,16 @@ var FieldMultiSelect = ({ form, input, isSubmitting }) => {
13011
13015
  children: [
13012
13016
  selectedValues.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-1", children: selectedValues.map((val) => {
13013
13017
  const option = lista.find(
13014
- (item) => getValue(item).toString() === val
13018
+ (item) => normalize(getValue(item)) === normalize(val)
13019
+ );
13020
+ return /* @__PURE__ */ jsxRuntime.jsx(
13021
+ Badge,
13022
+ {
13023
+ variant: "secondary",
13024
+ children: option?.name ?? val
13025
+ },
13026
+ `${input.name}-${normalize(val)}-ms`
13015
13027
  );
13016
- return /* @__PURE__ */ jsxRuntime.jsx(Badge, { variant: "secondary", children: option?.name ?? val }, `${input.name}-${val}-ms`);
13017
13028
  }) }) : /* @__PURE__ */ jsxRuntime.jsx("span", { children: input.placeHolder ?? "Selecciona..." }),
13018
13029
  /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronsUpDown, { className: "ml-2 h-4 w-4 opacity-50" })
13019
13030
  ]
@@ -13024,15 +13035,13 @@ var FieldMultiSelect = ({ form, input, isSubmitting }) => {
13024
13035
  /* @__PURE__ */ jsxRuntime.jsxs(CommandList, { children: [
13025
13036
  /* @__PURE__ */ jsxRuntime.jsx(CommandEmpty, { children: "No hay resultados." }),
13026
13037
  /* @__PURE__ */ jsxRuntime.jsx(CommandGroup, { children: lista.map((item) => {
13027
- const value = getValue(item).toString();
13028
- const selected = selectedValues.includes(value);
13038
+ const rawValue = getValue(item);
13039
+ const value = normalize(rawValue);
13040
+ const selected = selectedValues.map((v) => normalize(v)).includes(value);
13029
13041
  return /* @__PURE__ */ jsxRuntime.jsxs(
13030
13042
  CommandItem,
13031
13043
  {
13032
- onSelect: () => {
13033
- handleOnChage(value, input, field);
13034
- toggleOption(value);
13035
- },
13044
+ onSelect: () => toggleOption(rawValue),
13036
13045
  children: [
13037
13046
  /* @__PURE__ */ jsxRuntime.jsx(
13038
13047
  lucideReact.Check,
@@ -15219,7 +15228,8 @@ var DynamicForm = ({
15219
15228
  debug = false,
15220
15229
  isWrapInWizard = false,
15221
15230
  totalSteps = 0,
15222
- currentStep = 1
15231
+ currentStep = 1,
15232
+ submitBtnIcon = lucideReact.Save
15223
15233
  }) => {
15224
15234
  const [isPending, startTransition] = React3.useTransition();
15225
15235
  const schema = React3.useMemo(() => {
@@ -15294,7 +15304,7 @@ var DynamicForm = ({
15294
15304
  /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "h-5 w-5 mr-2 animate-spin" })
15295
15305
  ] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
15296
15306
  submitBtnLabel,
15297
- (totalSteps == 0 || totalSteps == currentStep) && /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Save, { className: "h-5 w-5 mr-2" })
15307
+ (totalSteps == 0 || totalSteps == currentStep) && submitBtnIcon && React3__namespace.default.createElement(submitBtnIcon, { className: "h-5 w-5 mr-2" })
15298
15308
  ] })
15299
15309
  }
15300
15310
  )