Open ghsolomon opened 2 months ago
Bumping this since it just came up again with another project. In this case, the initial data should be considered "invalid" until the user corrects it. It is also important to keep track of the dirty state (records the user hasn't yet corrected), ability to revert records, add records, etc.
Easiest workaround at the moment is this, but obviously not a long-term solution / prone to breaking changes / etc.
Object.defineProperty(gridModel.store.validator, "uncommittedRecords", {
get: function() {
return this.store.allRecords;
}
});
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 toloadData
andupdateData
as well (mainly for filtering - see https://github.com/xh/hoist-react/issues/2916). A couple ideas that have been raised:Store.validateCommittedRecords
flag to enable validation on all recordsRecord.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.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:
Grids
are being used asForms
, and the initial state is expected to be incomplete (similar to the initial state passed toFormModel.init
)