Skip to content

Instantly share code, notes, and snippets.

@bbqchickenrobot
Created October 29, 2020 17:24
Show Gist options
  • Select an option

  • Save bbqchickenrobot/c0b67c9ee15f789bd55d549a73f71948 to your computer and use it in GitHub Desktop.

Select an option

Save bbqchickenrobot/c0b67c9ee15f789bd55d549a73f71948 to your computer and use it in GitHub Desktop.
Blazorise DataGrid Validation
private async Task RowInserting(CancellableRowChange < FeatureToggle, Dictionary < String, Object >> e)
 {
log.LogInformation($ "values = {e.Values.ToJson()}");
log.LogInformation($ "validating feature {e.Item.Feature}");

if (string.IsNullOrEmpty(e.Item.Feature))
 {
log.LogError($ "validation failed for rule {e.Item.Dump()}");
toastService.ShowError($ "validation failed for {nameof(FeatureToggle)}. Feature name is required.");
e.Cancel = true;

}

else
 {
e.Cancel = false;

}

}

private async Task RowUpdating(CancellableRowChange < FeatureToggle, Dictionary < String, Object >> e)
 {
log.LogInformation($ "values = {e.Values.ToJson()}");
log.LogInformation($ "validating feature {e.Item.Feature}");

if (string.IsNullOrEmpty(e.Item.Feature))
 {
log.LogError($ "validation failed for rule {e.Item.Dump()}");
toastService.ShowError($ "validation failed for {nameof(FeatureToggle)}. Feature name is required.");
e.Cancel = true;

}

else
 {
e.Cancel = false;

}

}
@bbqchickenrobot
Copy link
Author

the values in the e.Item are always null..... not sure why as they should be included in the parameter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment