hoist-react icon indicating copy to clipboard operation
hoist-react copied to clipboard

Support validation of committed records

Open ghsolomon opened this issue 6 months ago • 0 comments

Currently, our RecordValidators only run on uncommitted records; however, we have come across a few client-apps that expect validation to run on records created via calls to loadData and updateData as well (mainly for filtering - see https://github.com/xh/hoist-react/issues/2916). A couple ideas that have been raised:

  • Add Store.validateCommittedRecords flag to enable validation on all records
  • Add Record.requiresValidation flag for more granular control per Record - could be set by app-developers by passing a flag to Store.loadData and Store.updateData. This is of course more complicated and may not be necessary for the current use cases.
  • An alternative approach for achieving more granular control per Record would be for Store.validateCommittedRecords to accept a boolean OR callback in the form of ((record: StoreRecord) => boolean). This might be more elegant, more flexible and less complicated than the approach mentioned above.

For context, a couple reasons apps may wish to validate programmatically added records:

  • When validation rules are configured to reflect certain business conditions users need to look out for. I.e. data is loaded from some external source, and validators flag potential problems for the user to resolve.
  • When Grids are being used as Forms, and the initial state is expected to be incomplete (similar to the initial state passed to FormModel.init)

ghsolomon avatar Aug 08 '24 22:08 ghsolomon