shadcn-zod-formkit 1.23.1 → 1.24.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
@@ -232,6 +232,11 @@ var entitiesToGroupedOption = (data, optionValue = "name") => {
232
232
  }
233
233
  return entities;
234
234
  };
235
+ var handleOnChage = (event, input, field) => {
236
+ console.log("\u{1F680} ~ handleOnChage ~ event:", event);
237
+ if (event) field?.onChange(event);
238
+ input.onChange?.(event);
239
+ };
235
240
 
236
241
  // src/components/custom/form/inputs/base/definitions.ts
237
242
  var flattenFields = (fields) => {
@@ -1667,13 +1672,14 @@ var GroupedSwitches = ({ options, onChange, input, isSubmitting }) => {
1667
1672
  setAllChecked(checked);
1668
1673
  onChange?.(updated.filter((opt) => opt.checked));
1669
1674
  };
1670
- const handleChildToggle = (option, checked) => {
1675
+ const handleChildToggle = (option, checked, input2) => {
1671
1676
  const updated = switches.map(
1672
1677
  (opt) => opt.id === option.id ? { ...opt, checked } : opt
1673
1678
  );
1674
1679
  setSwitches(updated);
1675
1680
  setAllChecked(updated.every((opt) => opt.checked));
1676
1681
  onChange?.(updated.filter((opt) => opt.checked));
1682
+ handleOnChage(updated.filter((opt) => opt.checked), input2);
1677
1683
  };
1678
1684
  return /* @__PURE__ */ jsxRuntime.jsx(Card, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn(`w-full h-full space-y-4 p-4 border-2 rounded-xl bg-green-500 ${allChecked ? "bg-green-500/5 border-green-400/10" : "bg-black/5"}`), children: [
1679
1685
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between border-b p-2", children: [
@@ -1691,7 +1697,7 @@ var GroupedSwitches = ({ options, onChange, input, isSubmitting }) => {
1691
1697
  disabled: input.disabled || isSubmitting,
1692
1698
  id: String(opt.id),
1693
1699
  checked: opt?.checked || false,
1694
- onCheckedChange: (checked) => handleChildToggle(opt, checked)
1700
+ onCheckedChange: (checked) => handleChildToggle(opt, checked, input)
1695
1701
  }
1696
1702
  )
1697
1703
  ] }, opt.id))
@@ -1732,7 +1738,7 @@ var AccordionGroupedSwitches = ({ form, input, groups = [], onChange, isSubmitti
1732
1738
  const countCheckedByGroup = (group) => {
1733
1739
  return group.options.filter((opt) => opt.checked).length;
1734
1740
  };
1735
- const handleOptionChange = (field, updatedGroupLabel, updatedOptions) => {
1741
+ const handleOptionChange = (field, updatedGroupLabel, updatedOptions, input2) => {
1736
1742
  const newGroups = groupsState.map(
1737
1743
  (group) => group.label === updatedGroupLabel ? { ...group, options: updatedOptions } : group
1738
1744
  );
@@ -1741,6 +1747,7 @@ var AccordionGroupedSwitches = ({ form, input, groups = [], onChange, isSubmitti
1741
1747
  setSelectedOptions(allChecked);
1742
1748
  field.onChange(allChecked);
1743
1749
  onChange?.(allChecked);
1750
+ handleOnChage(allChecked, input2, field);
1744
1751
  };
1745
1752
  return /* @__PURE__ */ jsxRuntime.jsx(
1746
1753
  FormField,
@@ -1771,7 +1778,7 @@ var AccordionGroupedSwitches = ({ form, input, groups = [], onChange, isSubmitti
1771
1778
  isSubmitting,
1772
1779
  input,
1773
1780
  options: group.options,
1774
- onChange: (updated) => handleOptionChange(field, group.label, updated)
1781
+ onChange: (updated) => handleOptionChange(field, group.label, updated, input)
1775
1782
  }
1776
1783
  ) })
1777
1784
  ]
@@ -1836,7 +1843,10 @@ var FieldButtonGroup = ({ input, form, isSubmitting, className = "w-full flex-1"
1836
1843
  type: "button",
1837
1844
  className,
1838
1845
  variant: selectedValue === option.value ? "default" : "outline",
1839
- onClick: () => handleSelect(option.value),
1846
+ onClick: () => {
1847
+ handleSelect(option.value);
1848
+ handleOnChage(option.value, input);
1849
+ },
1840
1850
  disabled: isSubmitting,
1841
1851
  children: option.label ?? option.name
1842
1852
  },
@@ -1861,6 +1871,7 @@ var CheckListInput = class extends BaseInput {
1861
1871
  /* @__PURE__ */ jsxRuntime.jsx(
1862
1872
  Checkbox,
1863
1873
  {
1874
+ onChange: (e) => handleOnChage(e, input),
1864
1875
  disabled: input.disabled || isSubmitting,
1865
1876
  id: String(item[optionValue]),
1866
1877
  checked: value.includes(item[optionValue]),
@@ -1912,7 +1923,7 @@ var FieldCheckbox = ({ input, form, isSubmitting }) => {
1912
1923
  {
1913
1924
  id: input.name,
1914
1925
  checked: field.value,
1915
- onCheckedChange: field.onChange,
1926
+ onCheckedChange: (e) => handleOnChage(e, input, field),
1916
1927
  disabled: input.disabled || isSubmitting,
1917
1928
  className: "data-[state=checked]:border-blue-600 data-[state=checked]:bg-blue-600 data-[state=checked]:text-white \n dark:data-[state=checked]:border-blue-700 dark:data-[state=checked]:bg-blue-700"
1918
1929
  }
@@ -1948,23 +1959,14 @@ var FieldColor = ({ form, input, isSubmitting }) => {
1948
1959
  ColorCmp,
1949
1960
  {
1950
1961
  value: field.value || "#000000",
1951
- onChange: field.onChange,
1962
+ onChange: (event) => {
1963
+ handleOnChage(event, input, field);
1964
+ },
1952
1965
  onBlur: field.onBlur,
1953
1966
  disabled: input.disabled || isSubmitting,
1954
1967
  placeholder: input.placeHolder
1955
1968
  }
1956
- ) : /* @__PURE__ */ jsxRuntime.jsx(
1957
- "input",
1958
- {
1959
- type: "color",
1960
- value: field.value || "#000000",
1961
- onChange: (e) => field.onChange(e.target.value),
1962
- onBlur: () => field.onBlur(),
1963
- disabled: input.disabled || isSubmitting,
1964
- placeholder: input.placeHolder,
1965
- style: { width: 48, height: 28 }
1966
- }
1967
- ) }),
1969
+ ) : "N/A" }),
1968
1970
  /* @__PURE__ */ jsxRuntime.jsx(FormDescription, { children: input.description }),
1969
1971
  /* @__PURE__ */ jsxRuntime.jsx(FormMessage, {})
1970
1972
  ] })
@@ -2185,6 +2187,7 @@ var FieldCombobox = ({ form, input, isSubmitting }) => {
2185
2187
  const newValue = currentValue === value ? "" : currentValue;
2186
2188
  setValue(newValue);
2187
2189
  form.setValue(input.name, newValue);
2190
+ handleOnChage(options.find((o) => getValue(o) === newValue), input);
2188
2191
  input.listConfig?.onOptionChange?.(
2189
2192
  options.find((o) => getValue(o) === newValue)
2190
2193
  );
@@ -2307,6 +2310,7 @@ var FieldCurrency = ({ form, input, isSubmitting }) => {
2307
2310
  setRawValue(newVal);
2308
2311
  const parsed = parseValue(newVal);
2309
2312
  if (parsed !== null) field.onChange(parsed);
2313
+ handleOnChage(parsed, input, field);
2310
2314
  },
2311
2315
  onBlur: (e) => {
2312
2316
  const formatted = formatValue(e.target.value);
@@ -3905,7 +3909,7 @@ var DateInput = class extends BaseInput {
3905
3909
  }, [field.value]);
3906
3910
  const handleSelect = (selectedDate) => {
3907
3911
  setDate(selectedDate);
3908
- field.onChange(selectedDate);
3912
+ handleOnChage(selectedDate, input, field);
3909
3913
  };
3910
3914
  return /* @__PURE__ */ jsxRuntime.jsxs(FormItem, { children: [
3911
3915
  /* @__PURE__ */ jsxRuntime.jsx(FormLabel, { children: /* @__PURE__ */ jsxRuntime.jsx("b", { children: input.label }) }),
@@ -3995,7 +3999,10 @@ var FieldDateTimeInput = ({ form, input, isSubmitting }) => {
3995
3999
  type: "datetime-local",
3996
4000
  value: dateTime,
3997
4001
  disabled: input.disabled || isSubmitting,
3998
- onChange: (e) => handleChange(e.target.value)
4002
+ onChange: (e) => {
4003
+ handleOnChage(e.target.value, input, field);
4004
+ handleChange(e.target.value);
4005
+ }
3999
4006
  }
4000
4007
  ),
4001
4008
  (iconsRight.length > 0 || textRight || autoValidate) && /* @__PURE__ */ jsxRuntime.jsxs(InputGroupAddon, { align: "inline-end", children: [
@@ -4055,6 +4062,7 @@ var FieldFile = ({ form, input, isSubmitting }) => {
4055
4062
  onChange: (e) => {
4056
4063
  field.onChange(e.target.files?.[0]);
4057
4064
  handleFileChange(e);
4065
+ handleOnChage(e.target.files?.[0], input, field);
4058
4066
  }
4059
4067
  }
4060
4068
  ) }),
@@ -4338,7 +4346,10 @@ var FieldMultiSelect = ({ form, input, isSubmitting }) => {
4338
4346
  return /* @__PURE__ */ jsxRuntime.jsxs(
4339
4347
  CommandItem,
4340
4348
  {
4341
- onSelect: () => toggleOption(value),
4349
+ onSelect: () => {
4350
+ handleOnChage(value, input, field);
4351
+ toggleOption(value);
4352
+ },
4342
4353
  children: [
4343
4354
  /* @__PURE__ */ jsxRuntime.jsx(
4344
4355
  lucideReact.Check,
@@ -4421,6 +4432,7 @@ var FieldTextGroup = ({ form, input, isSubmitting }) => {
4421
4432
  if (isNumberField) {
4422
4433
  value = e.target.value === "" ? "" : Number(e.target.value);
4423
4434
  }
4435
+ handleOnChage(value, input, field);
4424
4436
  field.onChange(value);
4425
4437
  }
4426
4438
  }
@@ -4478,7 +4490,7 @@ var FieldOTP = ({ form, input, isSubmitting }) => {
4478
4490
  name: input.name,
4479
4491
  render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(FormItem, { children: [
4480
4492
  /* @__PURE__ */ jsxRuntime.jsx(FormLabel, { children: /* @__PURE__ */ jsxRuntime.jsx("b", { children: input.label }) }),
4481
- /* @__PURE__ */ jsxRuntime.jsx(FormControl, { children: /* @__PURE__ */ jsxRuntime.jsx(InputOTP, { maxLength: totalPositions.length, ...field, children: /* @__PURE__ */ jsxRuntime.jsx(InputOTPGroup, { children: totalPositions.map((position) => /* @__PURE__ */ jsxRuntime.jsx(InputOTPSlot, { index: position }, position)) }) }) }),
4493
+ /* @__PURE__ */ jsxRuntime.jsx(FormControl, { children: /* @__PURE__ */ jsxRuntime.jsx(InputOTP, { maxLength: totalPositions.length, ...field, onChange: (event) => handleOnChage(event, input, field), children: /* @__PURE__ */ jsxRuntime.jsx(InputOTPGroup, { children: totalPositions.map((position) => /* @__PURE__ */ jsxRuntime.jsx(InputOTPSlot, { index: position }, position)) }) }) }),
4482
4494
  /* @__PURE__ */ jsxRuntime.jsx(FormDescription, { children: input.description }),
4483
4495
  /* @__PURE__ */ jsxRuntime.jsx(FormMessage, {})
4484
4496
  ] })
@@ -4519,7 +4531,7 @@ var FieldRadioGroup = ({ input, form, isSubmitting }) => {
4519
4531
  {
4520
4532
  ...field,
4521
4533
  value: field.value ?? "",
4522
- onValueChange: field.onChange,
4534
+ onValueChange: (e) => handleOnChage(e, input, field),
4523
4535
  className: "space-y-2 mt-3",
4524
4536
  children: options.map((opt, index) => /* @__PURE__ */ jsxRuntime.jsxs(
4525
4537
  "div",
@@ -4871,7 +4883,7 @@ var FieldSelect = ({ form, input, isSubmitting }) => {
4871
4883
  {
4872
4884
  disabled: input.disabled || isSubmitting || loading,
4873
4885
  onValueChange: (val) => {
4874
- field.onChange(val);
4886
+ handleOnChage(val, input, field);
4875
4887
  setValue(val);
4876
4888
  if (input.listConfig?.onOptionChange) {
4877
4889
  const selectedItem = lista.find(
@@ -4915,7 +4927,7 @@ var SimpleCheckListInput = class extends BaseInput {
4915
4927
  isSubmitting,
4916
4928
  input,
4917
4929
  value: field.value || [],
4918
- onChange: field.onChange
4930
+ onChange: (e) => handleOnChage(e, input, field)
4919
4931
  }
4920
4932
  )
4921
4933
  }
@@ -4937,12 +4949,14 @@ var FieldSimpleCheckList = ({ input, value, onChange, isSubmitting }) => {
4937
4949
  const handleMainToggle = (checked) => {
4938
4950
  const updated = options.map((opt) => ({ ...opt, checked }));
4939
4951
  setOptions(updated);
4952
+ handleOnChage(updated, input);
4940
4953
  onChange(updated);
4941
4954
  };
4942
4955
  const handleChildToggle = (option, checked) => {
4943
4956
  const updated = options.map(
4944
4957
  (opt) => opt.id === option.id ? { ...opt, checked } : opt
4945
4958
  );
4959
+ handleOnChage(updated, input);
4946
4960
  setOptions(updated);
4947
4961
  onChange(updated);
4948
4962
  };
@@ -5207,7 +5221,7 @@ var FieldSwitch = ({ input, form, isSubmitting }) => {
5207
5221
  Switch,
5208
5222
  {
5209
5223
  checked: field.value,
5210
- onCheckedChange: field.onChange,
5224
+ onCheckedChange: (event) => handleOnChage(event, input, field),
5211
5225
  "aria-disabled": true,
5212
5226
  disabled: input.disabled || isSubmitting
5213
5227
  }
@@ -5234,8 +5248,9 @@ var FieldTags = ({ input, form, isSubmitting }) => {
5234
5248
  /* @__PURE__ */ jsxRuntime.jsx(FormControl, { children: /* @__PURE__ */ jsxRuntime.jsx(
5235
5249
  TagsInput,
5236
5250
  {
5251
+ input,
5237
5252
  value: field.value ?? [],
5238
- onValueChange: field.onChange,
5253
+ onValueChange: (event) => handleOnChage(event, input, field),
5239
5254
  placeholder: "Enter for add tag"
5240
5255
  }
5241
5256
  ) }),
@@ -5250,6 +5265,7 @@ var SPLITTER_REGEX = /[\n#?=&\t,./-]+/;
5250
5265
  var FORMATTING_REGEX = /^[^a-zA-Z0-9]*|[^a-zA-Z0-9]*$/g;
5251
5266
  var TagsInput = React3__namespace.default.forwardRef(
5252
5267
  ({
5268
+ input,
5253
5269
  value,
5254
5270
  onValueChange,
5255
5271
  placeholder,
@@ -5264,7 +5280,7 @@ var TagsInput = React3__namespace.default.forwardRef(
5264
5280
  const parseMinItems = minItems ?? 0;
5265
5281
  const parseMaxItems = maxItems ?? Infinity;
5266
5282
  const addTag = (val) => {
5267
- if (!value.includes(val) && value.length < parseMaxItems) {
5283
+ if (!value.includes(val) && value.length < parseMaxItems || input.withDuplicatTag) {
5268
5284
  onValueChange([...value, val]);
5269
5285
  }
5270
5286
  };
@@ -5339,7 +5355,18 @@ function FieldTextArea({ form, input, isSubmitting }) {
5339
5355
  name: input.name,
5340
5356
  render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(FormItem, { className: "shadow-lg", children: [
5341
5357
  /* @__PURE__ */ jsxRuntime.jsx(FormLabel, { children: /* @__PURE__ */ jsxRuntime.jsx("b", { children: input.label }) }),
5342
- /* @__PURE__ */ jsxRuntime.jsx(FormControl, { children: /* @__PURE__ */ jsxRuntime.jsx(Textarea, { className: "min-w-[260px] bg-white", placeholder: input.placeHolder, ...field, disabled: input.disabled || isSubmitting }) }),
5358
+ /* @__PURE__ */ jsxRuntime.jsx(FormControl, { children: /* @__PURE__ */ jsxRuntime.jsx(
5359
+ Textarea,
5360
+ {
5361
+ className: "min-w-[260px] bg-white",
5362
+ placeholder: input.placeHolder,
5363
+ ...field,
5364
+ onChange: (event) => {
5365
+ handleOnChage(event, input, field);
5366
+ },
5367
+ disabled: input.disabled || isSubmitting
5368
+ }
5369
+ ) }),
5343
5370
  input.description && /* @__PURE__ */ jsxRuntime.jsx(FormDescription, { children: input.description }),
5344
5371
  /* @__PURE__ */ jsxRuntime.jsx(FormMessage, {})
5345
5372
  ] })
@@ -5370,6 +5397,7 @@ var FieldText = ({ input, form, isSubmitting }) => {
5370
5397
  placeholder: input.placeHolder,
5371
5398
  ...field,
5372
5399
  type,
5400
+ onChange: (e) => handleOnChage(e, input, field),
5373
5401
  disabled: input.disabled || isSubmitting
5374
5402
  }
5375
5403
  ) }),
@@ -5420,6 +5448,7 @@ var FieldTimeInput = ({ form, input, isSubmitting }) => {
5420
5448
  if (validNow !== isValid2) setIsValid(validNow);
5421
5449
  const handleChange = (val) => {
5422
5450
  setTime(val);
5451
+ handleOnChage(val, input, field);
5423
5452
  field.onChange(val);
5424
5453
  };
5425
5454
  return /* @__PURE__ */ jsxRuntime.jsxs(FormItem, { className: input.className, children: [
@@ -5655,7 +5684,7 @@ var DynamicForm = ({
5655
5684
  withErrorsAlert = true,
5656
5685
  errorAlertPosition = "up",
5657
5686
  withCard = false,
5658
- submitBtnClass = "text-lg w-1/4",
5687
+ submitBtnClass = "",
5659
5688
  listBtnConfig = [],
5660
5689
  submitBtnLabel = "Guardar",
5661
5690
  submitBtnLabelSubmiting = "Guardando...",
@@ -5714,7 +5743,7 @@ var DynamicForm = ({
5714
5743
  Button,
5715
5744
  {
5716
5745
  type: btn.btnType,
5717
- size: "icon-lg",
5746
+ size: "lg",
5718
5747
  className: submitBtnClass,
5719
5748
  variant: btn.variant,
5720
5749
  onClick: btn.onClick,
@@ -5727,7 +5756,7 @@ var DynamicForm = ({
5727
5756
  Button,
5728
5757
  {
5729
5758
  type: onClick ? "button" : "submit",
5730
- size: "icon-lg",
5759
+ size: "lg",
5731
5760
  className: cn(submitBtnClass),
5732
5761
  disabled: isPending,
5733
5762
  onClick: onClick ? handleClick : void 0,
@@ -6060,6 +6089,7 @@ exports.flattenFields = flattenFields;
6060
6089
  exports.getDefaultValues = getDefaultValues;
6061
6090
  exports.getDynamicSchema = getDynamicSchema;
6062
6091
  exports.getFieldLabel = getFieldLabel;
6092
+ exports.handleOnChage = handleOnChage;
6063
6093
  exports.inputFieldComp = inputFieldComp;
6064
6094
  exports.mockFields = mockFields;
6065
6095
  exports.useFormField = useFormField;