df-ae-forms-package 1.1.3 → 1.1.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/index.js CHANGED
@@ -1004,20 +1004,15 @@ const DfFormInput = ({ id, properties, validationErrors = {}, formValue = '', in
1004
1004
  touchedFields[id] = true;
1005
1005
  }
1006
1006
  }, [isTouched, id, touchedFields]);
1007
- // Reset touched state and value when switching modes
1007
+ // Reset touched state when switching modes
1008
1008
  React.useEffect(() => {
1009
+ setIsTouched(false);
1010
+ // Only reset value when explicitly moving to edit mode to show current default
1009
1011
  if (mode === 'edit') {
1010
- setIsTouched(false);
1011
- // Reset value to default value when switching to edit mode
1012
1012
  const defaultValue = properties?.basic?.defaultValue || '';
1013
1013
  setValue(defaultValue);
1014
1014
  }
1015
- else if (mode === 'test') {
1016
- setIsTouched(false);
1017
- // Reset value to empty when switching to test mode for fresh start
1018
- setValue('');
1019
- }
1020
- }, [mode, properties?.basic?.defaultValue]);
1015
+ }, [mode]);
1021
1016
  // Update value when formValue prop changes (but don't override user input)
1022
1017
  // CRITICAL: Only update if formValue is actually for THIS component's ID
1023
1018
  // Use componentIdRef to ensure we're checking against the correct component ID
@@ -4967,8 +4962,7 @@ const DfFormDataGrid = ({ id, properties, mode = 'edit', formData = {}, onValueC
4967
4962
  // This allows the form data to be updated for interactive components
4968
4963
  if (onValueChange) {
4969
4964
  onValueChange({
4970
- id: change.id,
4971
- value: change.value
4965
+ ...change
4972
4966
  });
4973
4967
  }
4974
4968
  }
@@ -5684,9 +5678,35 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
5684
5678
  return;
5685
5679
  }
5686
5680
  // CRITICAL: Check if multiple components share this ID (ID collision detection)
5687
- const componentsWithSameId = localFormComponents.filter(comp => comp.id === change.id);
5681
+ // Use recursive search for accurate detection across all levels
5682
+ const checkIdCollision = (components, targetId) => {
5683
+ let matches = [];
5684
+ components.forEach(comp => {
5685
+ if (ensureStringId$1(comp.id) === targetId)
5686
+ matches.push(comp);
5687
+ if (comp.name === 'section' && comp.children) {
5688
+ matches = [...matches, ...checkIdCollision(comp.children, targetId)];
5689
+ }
5690
+ if (comp.name === 'table' && comp.cells) {
5691
+ comp.cells.forEach((row) => {
5692
+ normalizeTableRow(row).forEach((cell) => {
5693
+ if (cell.components)
5694
+ matches = [...matches, ...checkIdCollision(cell.components, targetId)];
5695
+ });
5696
+ });
5697
+ }
5698
+ if (comp.name === 'datagrid' && comp.entries) {
5699
+ comp.entries.forEach((entry) => {
5700
+ if (entry.components)
5701
+ matches = [...matches, ...checkIdCollision(entry.components, targetId)];
5702
+ });
5703
+ }
5704
+ });
5705
+ return matches;
5706
+ };
5707
+ const componentsWithSameId = checkIdCollision(localFormComponents, change.id);
5688
5708
  if (componentsWithSameId.length > 1) {
5689
- console.error(`[DfFormPreview] ID COLLISION DETECTED! Multiple components share ID "${change.id}":`, componentsWithSameId.map(c => ({ id: c.id, name: c.name, label: c.basic?.label })));
5709
+ console.error(`[DfFormPreview] ID COLLISION DETECTED! Multiple components share ID "${change.id}":`, componentsWithSameId.map(c => ({ id: ensureStringId$1(c.id), name: c.name, label: c.basic?.label })));
5690
5710
  // Don't update - this would cause all components with this ID to get the same value
5691
5711
  return;
5692
5712
  }
@@ -5705,7 +5725,7 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
5705
5725
  }
5706
5726
  // Clear raised issues for this component when value changes
5707
5727
  // This ensures that if threshold condition changes, user must raise issue again
5708
- const component = localFormComponents.find(comp => comp.id === change.id);
5728
+ const component = findComponentById(localFormComponents, change.id);
5709
5729
  if (component) {
5710
5730
  const threshold = component?.threshold;
5711
5731
  if (threshold && threshold.conditions && threshold.conditions.length > 0) {
@@ -5721,7 +5741,8 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
5721
5741
  // Recursive function to update component values
5722
5742
  const updateComponentValue = (components) => {
5723
5743
  return components.map(component => {
5724
- if (component.id === change.id) {
5744
+ const componentId = ensureStringId$1(component.id);
5745
+ if (componentId === change.id) {
5725
5746
  // CRITICAL: Handle table/datagrid structure updates (cells, entries, etc.)
5726
5747
  // When a table sends onValueChange with cells data, update the whole component structure
5727
5748
  if (change.value && typeof change.value === 'object' && 'cells' in change.value) {
@@ -5737,13 +5758,12 @@ onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, select
5737
5758
  ...change.value
5738
5759
  };
5739
5760
  }
5740
- if ('defaultValue' in component.basic) {
5761
+ if ('value' in component.basic || 'defaultValue' in component.basic) {
5741
5762
  return {
5742
5763
  ...component,
5743
5764
  basic: {
5744
5765
  ...component.basic,
5745
- value: change.value ?? component.basic.defaultValue,
5746
- defaultValue: change.value
5766
+ value: change.value
5747
5767
  }
5748
5768
  };
5749
5769
  }