Hi,
I've the following issue related to Numeric Editor validator. In a MVC application I've defined in a controller the following grid column:
ColumnUpdatingSetting uSetTipoProdotto = new ColumnUpdatingSetting(); uSetTipoProdotto.ColumnKey = "TipoProdotto"; EditorValidatorOptions validOptTipoProdotto = new EditorValidatorOptions(); validOptTipoProdotto.BodyAsParent = false; validOptTipoProdotto.MinValue = 1; validOptTipoProdotto.MaxValue = 99; validOptTipoProdotto.Required = true; validOptTipoProdotto.CustomErrorMessage = "Il valore deve essere compreso tra 1 e 99 "; uSetTipoProdotto.NumericEditorOptions.ValidatorOptions = validOptTipoProdotto; uSetTipoProdotto.Validation = true; updating.ColumnSettings.Add(uSetTipoProdotto);
The goal is tp allow the values between 1 and 99 but the cose I've pasted is not working. What am I doing wrong?
Thank you in advance.
Kind regards.
Simone
Hi Simone,
Thanks for using Infragistics jquery controls.
The ValidatorOption exposed by XxxEditorValidator property of grid updating, uses shared EditorValidatorOptions class. That class exposes all options available for igValidator. However, if igValidator is attached to igEditor, then a particular editor may not support all options. For example, numeric editors (igEditor with type numeric, currency, percent) have their own min/maxValue and validator for min/max values is performed only for those options of igEditor. It means that application should use Max/MinValue properties of NumericEditorOptions.In your codes you should replace
validOptTipoProdotto.MinValue = 1;validOptTipoProdotto.MaxValue = 99;
by
uSetTipoProdotto.NumericEditorOptions.MaxValue = 99;uSetTipoProdotto.NumericEditorOptions.MinValue = 1;
There is no need to use
uSetTipoProdotto.Validation = true;
because validation was already enabled by
uSetTipoProdotto.NumericEditorOptions.ValidatorOptions = not_null_value;
The Validation is an alternative and it can be used to enable validation without setting ValidatorOptions. Example:
ColumnUpdatingSetting uSetTipoProdotto = new ColumnUpdatingSetting();uSetTipoProdotto.ColumnKey = "TipoProdotto";uSetTipoProdotto.NumericEditorOptions.MaxValue = 99;uSetTipoProdotto.NumericEditorOptions.MinValue = 1;uSetTipoProdotto.Validation = true;updating.ColumnSettings.Add(uSetTipoProdotto);
Note: if your application does not use igLoader (you may look at source of generated html), then in order for validators to work, corresponding js/css files should be available on client. If validator-error-message does not appear or it has wrong appearance, then application may include those files explicitly:
<link type="text/css" href="pathToLocation_probably:/css/structure/modules/infragistics.ui.validator.css" rel="stylesheet" /><script type="text/javascript" src="pathToLocation_probably:/js/modules/infragistics.ui.validator.js"></script>
thank you very much for the detailed explanation! Now it works when I edit a row but not when I add a row? Shall I add some more options?
thank you
regards
My bad! I've forgotten to define the editor type for a column!
Everything works, thank you very much!
Regards
Validators and editors should work within add-new-row same way as for row editing. Below are codes, which I used to experiment with your sample. I think, that you may test them by including few temporary files (view and model) into your project and copy/paste those codes.
View:<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<igGridComboEditor.Models.Validator>" %>...<%= Html.Infragistics().Grid("Grid1", Model.Grid1) %>
Model:
namespace igGridComboEditor.Models{ public class Validator { public GridModel Grid1 { get { GridModel grid = new GridModel(); grid.PrimaryKey = "ID"; grid.Columns.Add(new GridColumn("ID", "ID", "number", "100px")); grid.Columns.Add(new GridColumn("Product", "Product", "number", "100px")); grid.Columns.Add(new GridColumn("Text", "Text", "string", "100px")); List<GridRow> data = new List<GridRow>(); data.Add(new GridRow(0, 3, "ok1")); data.Add(new GridRow(1, 1, "ok2")); data.Add(new GridRow(3, 20, null)); grid.DataSource = data.AsQueryable(); GridUpdating updating = new GridUpdating(); ColumnUpdatingSetting uSetTipoProdotto = new ColumnUpdatingSetting(); uSetTipoProdotto.ColumnKey = "Product"; EditorValidatorOptions validOptTipoProdotto = new EditorValidatorOptions(); validOptTipoProdotto.BodyAsParent = false; validOptTipoProdotto.Required = true; validOptTipoProdotto.CustomErrorMessage = "Il valore deve essere compreso tra 1 e 99 "; uSetTipoProdotto.NumericEditorOptions.MaxValue = 99; uSetTipoProdotto.NumericEditorOptions.MinValue = 1; uSetTipoProdotto.NumericEditorOptions.ValidatorOptions = validOptTipoProdotto; updating.ColumnSettings.Add(uSetTipoProdotto);grid.Features.Add(updating); return grid; } }}public class GridRow{ public int ID { get; set; } public int Product { get; set; } public string Text { get; set; } public GridRow(int id, int product, string text) { this.ID = id; this.Product = product; this.Text = text; } }}