Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support validation of committed records #3751

Open
ghsolomon opened this issue Aug 8, 2024 · 1 comment
Open

Support validation of committed records #3751

ghsolomon opened this issue Aug 8, 2024 · 1 comment

Comments

@ghsolomon
Copy link
Contributor

ghsolomon commented Aug 8, 2024

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 #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
Copy link
Contributor Author

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;
    }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant