@dmitryvim/form-builder 0.3.3 → 0.3.4

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/esm/index.js CHANGED
@@ -848,7 +848,7 @@ function renderMultipleTextElement(element, ctx, wrapper, pathKey) {
848
848
  const readonly = isElementReadonly(element, state, ctx);
849
849
  const prefillValues = ctx.prefill[element.key] || [];
850
850
  const values = Array.isArray(prefillValues) ? [...prefillValues] : [];
851
- const minCount = element.minCount ?? 1;
851
+ const minCount = element.minCount ?? (element.required ? 1 : 0);
852
852
  const maxCount = element.maxCount ?? Infinity;
853
853
  while (values.length < minCount) {
854
854
  values.push(element.default || "");
@@ -1034,7 +1034,7 @@ function validateTextElement(element, key, context) {
1034
1034
  });
1035
1035
  if (!skipValidation) {
1036
1036
  const { state } = context;
1037
- const minCount = element.minCount ?? 1;
1037
+ const minCount = element.minCount ?? 0;
1038
1038
  const maxCount = element.maxCount ?? Infinity;
1039
1039
  const filteredValues = rawValues.filter((v) => v.trim() !== "");
1040
1040
  if (element.required && filteredValues.length === 0) {
@@ -1142,7 +1142,7 @@ function renderMultipleTextareaElement(element, ctx, wrapper, pathKey) {
1142
1142
  const readonly = isElementReadonly(element, state, ctx);
1143
1143
  const prefillValues = ctx.prefill[element.key] || [];
1144
1144
  const values = Array.isArray(prefillValues) ? [...prefillValues] : [];
1145
- const minCount = element.minCount ?? 1;
1145
+ const minCount = element.minCount ?? (element.required ? 1 : 0);
1146
1146
  const maxCount = element.maxCount ?? Infinity;
1147
1147
  while (values.length < minCount) {
1148
1148
  values.push(element.default || "");
@@ -1452,7 +1452,7 @@ function renderMultipleNumberElement(element, ctx, wrapper, pathKey) {
1452
1452
  const readonly = isElementReadonly(element, state, ctx);
1453
1453
  const prefillValues = ctx.prefill[element.key] || [];
1454
1454
  const values = Array.isArray(prefillValues) ? [...prefillValues] : [];
1455
- const minCount = element.minCount ?? 1;
1455
+ const minCount = element.minCount ?? (element.required ? 1 : 0);
1456
1456
  const maxCount = element.maxCount ?? Infinity;
1457
1457
  while (values.length < minCount) {
1458
1458
  values.push(element.default || "");
@@ -1623,7 +1623,7 @@ function validateNumberElement(element, key, context) {
1623
1623
  };
1624
1624
  if (element.multiple) {
1625
1625
  const inputs = scopeRoot.querySelectorAll(
1626
- `[name^="${key}["]`
1626
+ `[name^="${key}\\["]`
1627
1627
  );
1628
1628
  const values = [];
1629
1629
  inputs.forEach((input, index) => {
@@ -1647,7 +1647,7 @@ function validateNumberElement(element, key, context) {
1647
1647
  });
1648
1648
  if (!skipValidation) {
1649
1649
  const { state } = context;
1650
- const minCount = element.minCount ?? 1;
1650
+ const minCount = element.minCount ?? 0;
1651
1651
  const maxCount = element.maxCount ?? Infinity;
1652
1652
  const filteredValues = values.filter((v) => v !== null);
1653
1653
  if (element.required && filteredValues.length === 0) {
@@ -1766,7 +1766,7 @@ function renderMultipleSelectElement(element, ctx, wrapper, pathKey) {
1766
1766
  const readonly = isElementReadonly(element, state, ctx);
1767
1767
  const prefillValues = ctx.prefill[element.key] || [];
1768
1768
  const values = Array.isArray(prefillValues) ? [...prefillValues] : [];
1769
- const minCount = element.minCount ?? 1;
1769
+ const minCount = element.minCount ?? (element.required ? 1 : 0);
1770
1770
  const maxCount = element.maxCount ?? Infinity;
1771
1771
  while (values.length < minCount) {
1772
1772
  values.push(element.default || element.options?.[0]?.value || "");
@@ -1918,7 +1918,7 @@ function validateSelectElement(element, key, context) {
1918
1918
  if (skipValidation) return;
1919
1919
  const { state } = context;
1920
1920
  const filteredValues = values.filter(filterFn);
1921
- const minCount = "minCount" in element2 ? element2.minCount ?? 1 : 1;
1921
+ const minCount = "minCount" in element2 ? element2.minCount ?? 0 : 0;
1922
1922
  const maxCount = "maxCount" in element2 ? element2.maxCount ?? Infinity : Infinity;
1923
1923
  if (element2.required && filteredValues.length === 0) {
1924
1924
  errors.push(`${key2}: ${t("required", state)}`);
@@ -2195,7 +2195,7 @@ function renderMultipleSwitcherElement(element, ctx, wrapper, pathKey) {
2195
2195
  const state = ctx.state;
2196
2196
  const prefillValues = ctx.prefill[element.key] || [];
2197
2197
  const values = Array.isArray(prefillValues) ? [...prefillValues] : [];
2198
- const minCount = element.minCount ?? 1;
2198
+ const minCount = element.minCount ?? (element.required ? 1 : 0);
2199
2199
  const maxCount = element.maxCount ?? Infinity;
2200
2200
  while (values.length < minCount) {
2201
2201
  values.push(element.default || element.options?.[0]?.value || "");
@@ -2355,7 +2355,7 @@ function validateSwitcherElement(element, key, context) {
2355
2355
  if (skipValidation) return;
2356
2356
  const { state } = context;
2357
2357
  const filteredValues = values.filter(filterFn);
2358
- const minCount = "minCount" in el ? el.minCount ?? 1 : 1;
2358
+ const minCount = "minCount" in el ? el.minCount ?? 0 : 0;
2359
2359
  const maxCount = "maxCount" in el ? el.maxCount ?? Infinity : Infinity;
2360
2360
  if (el.required && filteredValues.length === 0) {
2361
2361
  errors.push(`${fieldKey}: ${t("required", state)}`);
@@ -5842,7 +5842,7 @@ function renderMultipleColourElement(element, ctx, wrapper, pathKey) {
5842
5842
  const readonly = isElementReadonly(element, state, ctx);
5843
5843
  const prefillValues = ctx.prefill[element.key] || [];
5844
5844
  const values = Array.isArray(prefillValues) ? [...prefillValues] : [];
5845
- const minCount = element.minCount ?? 1;
5845
+ const minCount = element.minCount ?? (element.required ? 1 : 0);
5846
5846
  const maxCount = element.maxCount ?? Infinity;
5847
5847
  while (values.length < minCount) {
5848
5848
  values.push(element.default || "#000000");
@@ -6028,7 +6028,7 @@ function validateColourElement(element, key, context) {
6028
6028
  });
6029
6029
  if (!skipValidation) {
6030
6030
  const { state } = context;
6031
- const minCount = element.minCount ?? 1;
6031
+ const minCount = element.minCount ?? 0;
6032
6032
  const maxCount = element.maxCount ?? Infinity;
6033
6033
  const filteredValues = values.filter((v) => v !== "");
6034
6034
  if (element.required && filteredValues.length === 0) {
@@ -6303,7 +6303,7 @@ function renderMultipleSliderElement(element, ctx, wrapper, pathKey) {
6303
6303
  const readonly = isElementReadonly(element, state, ctx);
6304
6304
  const prefillValues = ctx.prefill[element.key] || [];
6305
6305
  const values = Array.isArray(prefillValues) ? [...prefillValues] : [];
6306
- const minCount = element.minCount ?? 1;
6306
+ const minCount = element.minCount ?? (element.required ? 1 : 0);
6307
6307
  const maxCount = element.maxCount ?? Infinity;
6308
6308
  const defaultValue = element.default !== void 0 ? element.default : (element.min + element.max) / 2;
6309
6309
  while (values.length < minCount) {
@@ -6517,7 +6517,7 @@ function validateSliderElement(element, key, context) {
6517
6517
  });
6518
6518
  if (!skipValidation) {
6519
6519
  const { state } = context;
6520
- const minCount = element.minCount ?? 1;
6520
+ const minCount = element.minCount ?? 0;
6521
6521
  const maxCount = element.maxCount ?? Infinity;
6522
6522
  const filteredValues = values.filter((v) => v !== null);
6523
6523
  if (element.required && filteredValues.length === 0) {