Skip to content

Commit 0ef3100

Browse files
991769: Updated the UG content and samples for Editing in Blazor DataGrid
1 parent 0fb95d4 commit 0ef3100

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

blazor/datagrid/column-validation.md

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ documentation: ug
99

1010
# Validation in Blazor DataGrid
1111

12-
Validation is a critical aspect of maintaining data integrity in applications. The Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor DataGrid provides built-in support for efficient and reliable data validation. This feature ensures that entered or modified data adheres to predefined rules, helping prevent errors and maintain the accuracy of displayed information.
12+
Validation is essential for maintaining data integrity in applications. The Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor DataGrid provides built-in support for reliable data validation. This feature ensures that entered or modified data adheres to predefined rules, helping prevent errors and maintain the accuracy of displayed information.
1313

1414
## Column validation
1515

16-
Column validation ensures that edited or newly added row data meets specific criteria before being saved. This feature is useful for enforcing rules or constraints on individual columns to maintain data integrity. Validation rules can be defined using the [GridColumn.ValidationRules](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridColumn.html#Syncfusion_Blazor_Grids_GridColumn_ValidationRules) property, which specifies the conditions for validating column values. The validation mechanism utilizes the **Form Validator** library.
16+
Column validation ensures that edited or newly added row data meets specific criteria before being saved. This feature helps enforce rules or constraints on individual columns to maintain data integrity.
1717

18-
> Validation in the DataGrid is based on the Microsoft Blazor EditForm behavior. Once a validation message is displayed, the field is revalidated only during form submission or when focus is moved away from the field. Refer to the [Microsoft Validation](https://learn.microsoft.com/en-us/aspnet/core/blazor/forms/validation?view=aspnetcore-5.0#data-annotations-validator-component-and-custom-validation) documentation for additional details.
18+
Validation rules are defined using the [GridColum](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridColumn.html). [ValidationRules](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridColumn.html#Syncfusion_Blazor_Grids_GridColumn_ValidationRules) property, which specifies the conditions for validating column values. The validation mechanism uses the **Form Validator** library.
1919

20-
The following example demonstrates how to define a validation rule for a Grid column:
20+
> Validation in the DataGrid is based on the Microsoft Blazor EditForm behavior. Once a validation message is displayed, the field is revalidated only during form submission or when focus is moved away from the field. Refer to the [Microsoft Validation](https://learn.microsoft.com/en-us/aspnet/core/blazor/forms/validation?view=aspnetcore-5.0#data-annotations-validator-component-and-custom-validation) documentation for additional details.
2121
2222
{% tabs %}
2323
{% highlight razor tabtitle="Index.razor" %}
@@ -94,15 +94,15 @@ Data annotation validation attributes are used to validate fields in the Syncfus
9494
|---------------|--------------|
9595
| 1. RequiredAttribute<br>2. StringLengthAttribute<br>3. RangeAttribute<br>4. RegularExpressionAttribute<br>5. MinLengthAttribute<br>6. MaxLengthAttribute<br>7. EmailAddressAttribute<br>8. CompareAttribute<br>9. DataTypeAttribute<br>10. DataType.Custom<br>11. DataType.Date<br>12. DataType.DateTime<br>13. DataType.EmailAddress<br>14. DataType.ImageUrl<br>15. DataType.Url | These data annotation attributes are used as `validation rules` in DataGrid CRUD operations. |
9696

97-
For more information on data annotation, refer to this [documentation](https://blazor.syncfusion.com/documentation/datagrid/data-annotation) section.
97+
> For more details, refer to the [Data Annotation](https://blazor.syncfusion.com/documentation/datagrid/data-annotation) documentation.
9898
9999
## Custom validation
100100

101101
Custom validation enables the definition of validation logic tailored to specific application requirements.
102102

103-
To implement custom validation, create a class that inherits from the `ValidationAttribute` class and override the `IsValid` method. All custom validation logic should be placed within the `IsValid` method.
103+
To implement custom validation, define a class that inherits from the `ValidationAttribute` class and override the **IsValid** method. All validation logic should be placed within the **IsValid** method.
104104

105-
The following example demonstrates how to implement custom validation for the **EmployeeID** and **Freight** fields:
105+
In this configuration, custom validation is applied to the **EmployeeID** and **Freight** fields.
106106

107107
{% tabs %}
108108
{% highlight razor tabtitle="Index.razor" %}
@@ -225,7 +225,7 @@ public class CustomValidationFreight : ValidationAttribute
225225

226226
Complex data binding columns can be validated using the [ValidateComplexType](https://learn.microsoft.com/en-us/aspnet/core/blazor/forms/validation?view=aspnetcore-5.0#data-annotations-validator-component-and-custom-validation) attribute from data annotations.
227227

228-
In the following example, the `ValidateComplexType` attribute is applied to the **EmployeeName** class to enable validation of its properties. A custom validation message is displayed in the **First Name** column using the `RequiredAttribute` with a custom error message.
228+
In this configuration, the `ValidateComplexType` attribute is applied to the **EmployeeName** class to enable validation of its properties. A custom validation message is displayed in the **First Name** column using the `RequiredAttribute` with a custom error message.
229229

230230
{% tabs %}
231231
{% highlight razor tabtitle="Index.razor" %}
@@ -296,7 +296,7 @@ public class EmployeeInfo
296296
{% endhighlight %}
297297
{% endtabs %}
298298

299-
> Ensure the package **Microsoft.AspNetCore.Components.DataAnnotations.Validation** is included to enable complex type validation. Use the following reference:
299+
> Ensure the package **Microsoft.AspNetCore.Components.DataAnnotations.Validation** is referenced to enable complex type validation. Use the following declaration:
300300
301301
```csharp
302302
<PackageReference Include="Microsoft.AspNetCore.Components.DataAnnotations.Validation" Version="3.2.0-rc1.20223.4" />
@@ -307,17 +307,18 @@ public class EmployeeInfo
307307

308308
## Custom validator component
309309

310-
In scenarios where built-in or attribute-based validation is insufficient, a custom validator component can be implemented to validate the Grid edit form. This is achieved using the [Validator](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridEditSettings.html#Syncfusion_Blazor_Grids_GridEditSettings_Validator) property of the [GridEditSettings](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridEditSettings.html) component, which accepts a validation component and injects it into the EditForm of the DataGrid.
310+
In scenarios where built-in or attribute-based validation is insufficient, a custom validator component can be used to validate the Grid edit form. This is configured using the [Validator](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridEditSettings.html#Syncfusion_Blazor_Grids_GridEditSettings_Validator) property of the [GridEditSettings](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridEditSettings.html) , which accepts a validation component and injects it into the EditForm of the DataGrid.
311311
312-
Within the custom validator component, data can be accessed using the implicit context parameter, which is of type [ValidatorTemplateContext](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.ValidatorTemplateContext.html).
312+
Within the custom validator component, data can be accessed using the implicit context parameter of type [ValidatorTemplateContext](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.ValidatorTemplateContext.html).
313313
314-
For guidance on creating a form validator component, refer to the [official documentation](https://learn.microsoft.com/en-us/aspnet/core/blazor/forms-and-input-components?view=aspnetcore-5.0#validator-components).
315-
In the following example:
314+
In this configuration:
316315

317-
* A form validator component named **MyCustomValidator** is created, accepting a `ValidatorTemplateContext` value as a parameter.
318-
* The **MyCustomValidator** component is assigned to the `Validator` property.
319-
* The component validates whether the **Freight** value is between **0** and **100**.
320-
* Validation error messages are displayed using the **ValidationMessage** component.
316+
- A form validator component named **MyCustomValidator** is created, accepting a `ValidatorTemplateContext` value as a parameter.
317+
- The **MyCustomValidator** component is assigned to the `Validator` property.
318+
- The component validates whether the **Freight** value is between **0** and **100**.
319+
- Validation error messages are displayed using the **ValidationMessage** component.
320+
321+
> For guidance on creating a form validator component, refer to the official [documentation](https://learn.microsoft.com/en-us/aspnet/core/blazor/forms-and-input-components?view=aspnetcore-5.0#validator-components).
321322
322323
```csharp
323324
[MyCustomValidator.cs]
@@ -405,9 +406,9 @@ public class MyCustomValidator : ComponentBase
405406

406407
## Display validation message using in-built tooltip
407408

408-
When using **Inline** or **Batch** editing modes in the Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor DataGrid, the **ValidationMessage** component may not be suitable for displaying error messages. In such cases, the built-in validation tooltip can be used to show validation messages by invoking the [ValidatorTemplateContext.ShowValidationMessage(fieldName, isValid, message)](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.ValidatorTemplateContext.html#Syncfusion_Blazor_Grids_ValidatorTemplateContext_ShowValidationMessage) method.
409+
When using [Inline](https://blazor.syncfusion.com/documentation/datagrid/in-line-editing) or [Batch](https://blazor.syncfusion.com/documentation/datagrid/batch-editing) editing modes in the Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor DataGrid, the **ValidationMessage** component may not be suitable for displaying error messages. In such cases, the built-in validation tooltip can be used by invoking the [ShowValidationMessage](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.ValidatorTemplateContext.html#Syncfusion_Blazor_Grids_ValidatorTemplateContext_ShowValidationMessage) method.
409410
410-
The `HandleValidation` method of the **MyCustomValidator** component can be updated as shown below:
411+
The **HandleValidation** method of the **MyCustomValidator** component can be updated to display validation messages using tooltips, as shown below:
411412

412413
```c#
413414
protected void HandleValidation(FieldIdentifier identifier)
@@ -438,10 +439,12 @@ protected void HandleValidation(FieldIdentifier identifier)
438439

439440
## Disable in-built validator component
440441

441-
The [Validator](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridEditSettings.html#Syncfusion_Blazor_Grids_GridEditSettings_Validator) property of the [GridEditSettings](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridEditSettings.html) component can be used to disable the built-in validator component in the Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor DataGrid. By default, the Grid uses two validator components:
442+
The [Validator](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridEditSettings.html#Syncfusion_Blazor_Grids_GridEditSettings_Validator) property of the [GridEditSettings](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridEditSettings.html) component can be used to disable the built-in `Validator` component in the Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor DataGrid.
443+
444+
By default, the Grid uses two validator components:
442445

443-
* DataAnnotationsValidator
444-
* An internal validator that processes the `ValidationRules` property
446+
- DataAnnotationsValidator
447+
- An internal validator that processes the [ValidationRules](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridColumn.html#Syncfusion_Blazor_Grids_GridColumn_ValidationRules) property
445448
446449
To use only the **DataAnnotationsValidator** component and disable the internal validator, configure the Validator property as shown below:
447450

@@ -473,10 +476,9 @@ To use only the **DataAnnotationsValidator** component and disable the internal
473476

474477
## Display validation message in dialog template
475478

476-
Use form validation to show a validation message for a field that is not defined as a column in the Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor DataGrid.
477-
The [Validator](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridEditSettings.html#Syncfusion_Blazor_Grids_GridEditSettings_Validator) property can be used to display a validation message for a field within the dialog template, even if the field is not included in the Grid columns.
479+
The Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor DataGrid supports form validation for fields that are not defined as columns. The [Validator](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.GridEditSettings.html#Syncfusion_Blazor_Grids_GridEditSettings_Validator) property can be used to display a validation message for such fields within the [dialog template](https://blazor.syncfusion.com/documentation/datagrid/template-editing#dialog-template-editing).
478480
479-
In the following example, the validation message for **ShipAddress** is shown in the dialog template, although the **ShipAddress** field is not defined as a Grid column.
481+
In this configuration, the validation message for **ShipAddress** is displayed in the dialog template, although the **ShipAddress** field is not defined as a Grid column.
480482

481483
> Validation messages for fields not defined in the Grid columns will appear as a validation summary at the top of the dialog edit form.
482484

0 commit comments

Comments
 (0)