-
Notifications
You must be signed in to change notification settings - Fork 305
allowCalculateOverride does not reliably preserve manual overrides with Logic or Calculated Values #639
Description
When using allowCalculateOverride: true, manually overridden values should be preserved. However, both Logic (change event) and Calculated Value mechanisms override the user-entered value during form load or recalculation.
This makes it difficult to implement dependent fields that allow users to override automatically calculated values.
Scenario
Two datetime fields:
riskInceptionDateriskExpiryDate
Expiry should be automatically calculated as:
moment(data.riskInceptionDate).add(365, 'days')but users must be able to manually override the expiry date.
Attempt 1 – Using Logic (Change Event)
Logic on riskInceptionDate:
if (data.riskInceptionDate) {
data.riskExpiryDate = moment(data.riskInceptionDate)
.add(365, 'days')
.toDate();
}riskExpiryDate configuration:
"allowCalculateOverride": trueProblem
When loading submission data:
- Form loads submission values
setValue()fireschangeevents- Logic runs again
riskExpiryDateis recalculated- The manually overridden value is overwritten
Attempt 2 – Using Calculated Value
Calculated Value for riskExpiryDate:
if (data.riskInceptionDate) {
value = moment(data.riskInceptionDate)
.add(365, 'days')
.toDate();
}allowCalculateOverride enabled.
Problem
Calculated Value continues to recompute when the form recalculates, which overwrites the manually overridden value when the form loads or when dependent fields update.
Actual Behavior
Manual overrides are not preserved consistently when:
- the form loads submission data
- dependent fields trigger recalculation
- logic runs through
changeevents
Expected Behavior
When allowCalculateOverride is enabled:
- Logic or Calculated Values should not overwrite an existing user-entered value.
- Manual overrides should persist after form reload or recalculation.
Impact
This prevents reliable implementation of common patterns such as:
- auto-calculating policy expiry dates
- auto-populating dependent fields while still allowing user overrides
Developers must implement complex workarounds (flags, hidden fields, conditional checks) to preserve overrides.
Environment
- Form.io version:
"@formio/js": "^5.2.5", "@formio/react": "^6.1.2" - Components affected:
datetime, but likely applies to other calculated fields as well