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