hoist-react
hoist-react copied to clipboard
Support validation of committed records
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 perRecord
- could be set by app-developers by passing a flag toStore.loadData
andStore.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 forStore.validateCommittedRecords
to accept aboolean
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 asForms
, and the initial state is expected to be incomplete (similar to the initial state passed toFormModel.init
)