Hello,
i am using NetAdvantage 2012.1 and would like to know if grid editor are supporting DataAnnotation validation.
Thank you
Hardis
I'm afraid that there are a couple of inconsistencies that cause your configuration to be invalid:1. You define the Updating feature twice - our MVC wrapper does not aggregate (feature) definitions so you will need to move the .Validation(true); part into the first (which should be the only definition of the Updating feature).The confusion stems from the fact that some MVC wrappers (or jQuery widgets) allow multiple definitions which are then aggregated. However our MVC wrappers and jQuery widgets rely on single definitions but since subsequent definitions are allowed by the frameworks, those defitions override the original definitions.2. I'm afraid that you cannot trick the MVC wrapper into allowing you to set options for the igValidator in such a pretty way (using chaining):
.TextEditorOptions(options => { options.ValidatorOptions(option => { options.ValidatorOptions(validOptions => { validOptions.OnChange(true); }); }); })
You will need to use the raw configuration using the ValidatorOptions method like so:
.EditorOptions(@"validatorOptions: {errorLabel: 'GridValidation', onChange: true}");
Also, setting the onChange trigger for validation won't have much effect on a text editor as having an empty value is OK with it. Instead I can recommend using the Updating columnSetting .Required(true) option as it will trigger validation without any problems.Hope this has helped clear things up a bit - let us know if you run into any other issues.
Thanks for your answer.
I have tested and there no Data Annotation of .NET framework displayed in Data Grid.
Here is the code :
index.cshtml :
<div id="result"> @(Html.Infragistics().Grid(Model).ID("grid2").Height("700px").PrimaryKey("Id").UpdateUrl("EditionUserLogin").Columns(column =>{ column.For(x => x.Id).HeaderText("Id").Width("50px"); column.For(x => x.Prenom).HeaderText(HttpContext.GetGlobalResourceObject("UserLogin", "ColonnePrenom").ToString()).Width("150px"); column.For(x => x.Nom).HeaderText(HttpContext.GetGlobalResourceObject("UserLogin", "ColonneNom").ToString()).Width("200px"); column.For(x => x.Login).HeaderText(HttpContext.GetGlobalResourceObject("UserLogin", "ColonneLogin").ToString()).Width("200px"); column.For(x => x.Mail).HeaderText(HttpContext.GetGlobalResourceObject("UserLogin", "ColonneMail").ToString()).Width("200px"); column.For(x => x.Telephone).HeaderText(HttpContext.GetGlobalResourceObject("UserLogin", "ColonneTel").ToString()).Width("150px");}).AutoCommit(true).Features(features => { features.Sorting(); features.Paging().PageSize(30); features.Updating().ColumnSettings(settings => { settings.ColumnSetting().ColumnKey("Id").EditorType(ColumnEditorType.Text).ReadOnly(true); settings.ColumnSetting().ColumnKey("Prenom").EditorType(ColumnEditorType.Text) .TextEditorOptions(options => { options.ValidatorOptions(option => { options.ValidatorOptions(validOptions => { validOptions.OnChange(true); }); }); }).EditorOptions(@"validatorOptions: {errorLabel: 'GridValidation'}"); settings.ColumnSetting().ColumnKey("Nom").EditorType(ColumnEditorType.Text) .TextEditorOptions(options => { options.ValidatorOptions(option => { options.ValidatorOptions(validOptions => validOptions.OnChange(true)); }); }).EditorOptions(@"validatorOptions: {errorLabel: 'GridValidation'}"); settings.ColumnSetting().ColumnKey("Login").EditorType(ColumnEditorType.Text) .TextEditorOptions(options => { options.ValidatorOptions(option => { options.ValidatorOptions(validOptions => validOptions.OnChange(true)); }); }).EditorOptions(@"validatorOptions: {errorLabel: 'GridValidation'}"); settings.ColumnSetting().ColumnKey("Mail").EditorType(ColumnEditorType.Text) .TextEditorOptions(options => { options.ValidatorOptions(option => { options.ValidatorOptions(validOptions => validOptions.OnChange(true)); }); }).EditorOptions(@"validatorOptions: {errorLabel: 'GridValidation'}"); settings.ColumnSetting().ColumnKey("Telephone").EditorType(ColumnEditorType.Text) .TextEditorOptions(options => { options.ValidatorOptions(option => { options.ValidatorOptions(validOptions => validOptions.OnChange(true)); }); }).EditorOptions(@"validatorOptions: {errorLabel: 'GridValidation'}"); }); features.Filtering(); features.Hiding(); features.Resizing(); features.Updating().Validation(true); }).DataSourceUrl(Url.Action("ChargerUserLogin")).DataBind().Render() ) @*@Html.Infragistics*@ </div> <div id="validationError"> <span class="field-validation-valid" data-valmsg-for="GridValidation" data-valmsg-replace="true"> </span> </div>
Here is the business object :
public class UserLogin { /// <summary> /// Gets or sets the id . /// </summary> /// <value> /// The id. /// </value> public int Id { get; set; } /// <summary> /// Gets or sets the nom. /// </summary> /// <value> /// The nom. /// </value> [Required(AllowEmptyStrings = false, ErrorMessage = "Le nom ne peut être nul.")] public string Nom { get; set; } /// <summary> /// Gets or sets the prenom. /// </summary> /// <value> /// The prenom. /// </value> [Required(AllowEmptyStrings = false, ErrorMessage = "Le prénom ne peut être nul.")] public string Prenom { get; set; } /// <summary> /// Gets or sets the login. /// </summary> /// <value> /// The login. /// </value> [Required(AllowEmptyStrings = false, ErrorMessage = "Le login ne peut être nul.")] public string Login { get; set; } /// <summary> /// Gets or sets the mail. /// </summary> /// <value> /// The mail. /// </value> [RegularBLOCKED EXPRESSION] public string Telephone { get; set; } }
Do i make something wrong ?
Hi Hardis,Yes, any igEditor that you use in the igGrid's Updating feature can have data annotation validation.It's currently not described in the documentation and in the igEditors data annotation validation sample, but here's a breakdown of the logic that you need to be aware of:1. The data annotation validation is handled by the igValidator's errorLabel option - you can see more details on it here: https://www.igniteui.com/help/api/2019.1/ui.igvalidator#options:errorMessage 2. Each igEditor you use can have its own set ot validation options configured via the validatorOptions option (more info at https://www.igniteui.com/help/igvalidator-migration-topic#options_changes) 3. When using the igGrid's Updating feature, you can use the columnSettings option (https://www.igniteui.com/help/iggrid-columnmoving-propertyreference#columnSettings) to tweak the igEditor used for a specific column. The editorOptions options is the one to take note of.When we put the knowledge for all of these together, you're almost ready with the data annotation validation. The final piece of the puzzle is to have a SPAN, LABEL or DIV element on your page that has the data-valmsg-for attribute that corresponds to the errorLabel you've set for the igValidator, used for the validation of an igEditor used by the igGrid Updating feature. For example:[code]<span class="field-validation-valid" data-valmsg-for="ProductIDValidationError" data-valmsg-replace="true"></span>[/code]
I know it may sound difficult, but it's not :). To make sure I'm not lying to you, I've attached a simple HTML page to my reply where you can see the data annotation validation in action.Currently only the ProductID column is configured to have it, but I think that's enough to illustrate the concept.
Let us know if you have any trouble or further questions.Cheers!Borislav