@dmitryvim/form-builder 0.2.15 → 0.2.16

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
@@ -3691,6 +3691,18 @@ function updateSliderField(element, fieldPath, value, context) {
3691
3691
  }
3692
3692
 
3693
3693
  // src/components/container.ts
3694
+ function extractChildDefaults(elements) {
3695
+ const defaults = {};
3696
+ for (const child of elements) {
3697
+ if ("default" in child && child.default !== void 0) {
3698
+ defaults[child.key] = child.default;
3699
+ }
3700
+ }
3701
+ return defaults;
3702
+ }
3703
+ function mergeWithDefaults(prefill, defaults) {
3704
+ return { ...defaults, ...prefill };
3705
+ }
3694
3706
  function extractRootFormData(formRoot) {
3695
3707
  const data = {};
3696
3708
  const inputs = formRoot.querySelectorAll(
@@ -3765,10 +3777,13 @@ function renderSingleContainerElement(element, ctx, wrapper, pathKey) {
3765
3777
  containerWrap.appendChild(hintsElement);
3766
3778
  }
3767
3779
  }
3780
+ const childDefaults = extractChildDefaults(element.elements);
3781
+ const containerPrefill = ctx.prefill?.[element.key] || {};
3782
+ const mergedPrefill = mergeWithDefaults(containerPrefill, childDefaults);
3768
3783
  const subCtx = {
3769
3784
  path: pathJoin(ctx.path, element.key),
3770
- prefill: ctx.prefill?.[element.key] || {},
3771
- // Sliced data for value population
3785
+ prefill: mergedPrefill,
3786
+ // Merged prefill with defaults for enableIf evaluation
3772
3787
  formData: ctx.formData ?? ctx.prefill,
3773
3788
  // Complete root data for enableIf evaluation
3774
3789
  state: ctx.state
@@ -3798,6 +3813,7 @@ function renderMultipleContainerElement(element, ctx, wrapper, _pathKey) {
3798
3813
  const min = element.minCount ?? 0;
3799
3814
  const max = element.maxCount ?? Infinity;
3800
3815
  const pre = Array.isArray(ctx.prefill?.[element.key]) ? ctx.prefill[element.key] : null;
3816
+ const childDefaults = extractChildDefaults(element.elements);
3801
3817
  const countItems = () => itemsWrap.querySelectorAll(":scope > .containerItem").length;
3802
3818
  const createAddButton = () => {
3803
3819
  const add = document.createElement("button");
@@ -3824,7 +3840,8 @@ function renderMultipleContainerElement(element, ctx, wrapper, _pathKey) {
3824
3840
  const subCtx = {
3825
3841
  state: ctx.state,
3826
3842
  path: pathJoin(ctx.path, `${element.key}[${idx}]`),
3827
- prefill: {},
3843
+ prefill: childDefaults,
3844
+ // Defaults for enableIf evaluation
3828
3845
  formData: currentFormData
3829
3846
  // Current root data from DOM for enableIf
3830
3847
  };
@@ -3887,10 +3904,12 @@ function renderMultipleContainerElement(element, ctx, wrapper, _pathKey) {
3887
3904
  };
3888
3905
  if (pre && Array.isArray(pre)) {
3889
3906
  pre.forEach((prefillObj, idx) => {
3907
+ const mergedPrefill = mergeWithDefaults(prefillObj || {}, childDefaults);
3890
3908
  const subCtx = {
3891
3909
  state: ctx.state,
3892
3910
  path: pathJoin(ctx.path, `${element.key}[${idx}]`),
3893
- prefill: prefillObj || {},
3911
+ prefill: mergedPrefill,
3912
+ // Merged prefill with defaults for enableIf
3894
3913
  formData: ctx.formData ?? ctx.prefill
3895
3914
  // Complete root data for enableIf
3896
3915
  };
@@ -3942,7 +3961,8 @@ function renderMultipleContainerElement(element, ctx, wrapper, _pathKey) {
3942
3961
  const subCtx = {
3943
3962
  state: ctx.state,
3944
3963
  path: pathJoin(ctx.path, `${element.key}[${idx}]`),
3945
- prefill: {},
3964
+ prefill: childDefaults,
3965
+ // Defaults for enableIf evaluation
3946
3966
  formData: ctx.formData ?? ctx.prefill
3947
3967
  // Complete root data for enableIf
3948
3968
  };
@@ -4297,7 +4317,8 @@ function shouldDisableElement(element, ctx) {
4297
4317
  }
4298
4318
  try {
4299
4319
  const rootFormData = ctx.formData ?? ctx.prefill ?? {};
4300
- const containerData = ctx.path ? getValueByPath(rootFormData, ctx.path) : void 0;
4320
+ const scope = element.enableIf.scope ?? "relative";
4321
+ const containerData = scope === "relative" && ctx.path ? ctx.prefill : void 0;
4301
4322
  const shouldEnable = evaluateEnableCondition(
4302
4323
  element.enableIf,
4303
4324
  rootFormData,