DataGridRowValidator : Mark the Model property as virtual#7771
Merged
ScarletKuro merged 1 commit intoMudBlazor:devfrom Mar 7, 2024
Merged
Conversation
…that it can be overriden. Existing DatagridRowValidator.Model throws the NotImplementedexception when accessed.
Member
|
Hi. |
ScarletKuro
approved these changes
Mar 7, 2024
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #7794
Marked the Model property on the DataGridRowValidator as virtual so, that it can be overriden. Existing DatagridRowValidator.Model throws the NotImplementedexception when accessed. See open discussion for more details: #7767
Description
I would like to use the built in mudblazor validation (For) in the MudDataGrid in combination with the FluentValidator. That could potentially be done quite nicely in a similar clean way as it's already possible with other controls like MudTextField.
Here is the problem:
MudDataGrid.razor.cs contains the validator property:
public Interfaces.IForm Validator { get; set; } = new DataGridRowValidator();There is currently no working implementation in place for the DataGrid and trying to use the mentioned validator leads to a crash because of the following implementation in the DataGridRowValidator :
public object? Model { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); }The MudFormComponent would start the validation using "For" and crashes because of Form?.Model
The implementation is just not in place yet, which is perfectly fine.
Unfortunately it is currently impossible to extend or override the functionality because of the Model Property implementation (or rather the fact that it's missing and throws an exception) on the DataGridRowValidator. It's also impossible to provide a completely new implementation for the IForm since some of te properties are marked as internal.
The easiest solution would probably be to mark the Model property on the DataGridRowValidator as virtual
The alternative would be to allow setting of Model on DataGridRowValidator. If you would prefer that let me know and I'll provide a new PR.
How Has This Been Tested?
I've created a small application to check whether the change would suffice for what I was intending to do. (override model and provide my own implementation. Honestly a normal get/set instead of an exception would have probably already be enough but I just wanted to have as little of an impact as possible.
Types of changes
Checklist:
dev).