df-ae-forms-package 1.0.93 → 1.0.95

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.esm.js CHANGED
@@ -4710,6 +4710,13 @@ formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, onNotesChan
4710
4710
  const DfFormDataGrid = ({ id, properties, mode = 'edit', formData = {}, onValueChange, onSelect, isSelected = false, className = '', onDataGridSelect, onComponentSelect, onComponentDelete, onComponentEdit, onComponentUpdate, selectedComponent, renderFormComponent, onEntryAdd, onEntryRemove, formTemplateId, onThresholdActionCompletion, onThresholdIssueRaised, onNotesChange, onAttachmentChange, shouldShowComponent }) => {
4711
4711
  const [isCollapsed, setIsCollapsed] = useState(false);
4712
4712
  const hasInitialized = useRef(false);
4713
+ // Use a ref for localFormData so renderComponent doesn't need it in deps
4714
+ // This prevents DfFormInput from resetting its internal state on every keystroke
4715
+ const localFormDataRef = useRef({ ...formData });
4716
+ // Keep ref in sync with formData prop (parent updates), but never overwrite user-typed values
4717
+ useEffect(() => {
4718
+ localFormDataRef.current = { ...formData, ...localFormDataRef.current };
4719
+ }, [formData]);
4713
4720
  // Get all components in the grid and sanitize them to ensure no data leaks into templates
4714
4721
  let gridComponents = (properties.templateComponents || []).map(comp => ({
4715
4722
  ...comp,
@@ -4924,8 +4931,10 @@ const DfFormDataGrid = ({ id, properties, mode = 'edit', formData = {}, onValueC
4924
4931
  // Handle component value change for form data updates (test mode)
4925
4932
  const handleComponentValueChange = useCallback((change) => {
4926
4933
  if (mode === 'test') {
4927
- // In test mode, update form data through the parent's onValueChange
4928
- // This allows the form data to be updated for interactive components
4934
+ // CRITICAL: Update localFormDataRef immediately so the value persists in the UI
4935
+ // without waiting for the parent round-trip (which resets values for entry 2+)
4936
+ localFormDataRef.current = { ...localFormDataRef.current, [change.id]: change.value };
4937
+ // Also propagate up to parent for persistence
4929
4938
  if (onValueChange) {
4930
4939
  onValueChange({
4931
4940
  id: change.id,
@@ -4989,7 +4998,12 @@ const DfFormDataGrid = ({ id, properties, mode = 'edit', formData = {}, onValueC
4989
4998
  }, [properties, onValueChange, id, onEntryRemove]);
4990
4999
  // Use our own render function to ensure proper onComponentUpdate handling
4991
5000
  const renderComponent = useCallback((field, hideLabel = false) => {
4992
- const formValue = mode === 'test' ? (formData[field.id] || ('defaultValue' in field.basic ? field.basic.defaultValue || '' : '')) : ('defaultValue' in field.basic ? field.basic.defaultValue || '' : '');
5001
+ // CRITICAL: Use localFormDataRef (not formData prop) so values persist in entry 2+ immediately
5002
+ // Also fall back to field.basic.value which is updated by DfFormPreview's updateComponentValue after round-trip
5003
+ const effectiveFormData = { ...formData, ...localFormDataRef.current };
5004
+ const formValue = mode === 'test'
5005
+ ? (effectiveFormData[field.id] ?? field.basic?.value ?? ('defaultValue' in field.basic ? field.basic.defaultValue || '' : ''))
5006
+ : ('defaultValue' in field.basic ? field.basic.defaultValue || '' : '');
4993
5007
  const commonProps = {
4994
5008
  id: field.id,
4995
5009
  properties: field,
@@ -5046,7 +5060,7 @@ const DfFormDataGrid = ({ id, properties, mode = 'edit', formData = {}, onValueC
5046
5060
  default:
5047
5061
  return jsxs("div", { className: "unknown-component", children: ["Unknown component: ", field.name] });
5048
5062
  }
5049
- }, [mode, handleComponentValueChange]);
5063
+ }, [mode, handleComponentValueChange, formData]);
5050
5064
  const gridStyle = {
5051
5065
  backgroundColor: properties.styles.backgroundColor || 'var(--df-color-fb-container)',
5052
5066
  borderColor: properties.styles.borderColor || 'var(--df-color-fb-border)',