Incorrect generate validator for model with RegularExpression attribute

2 posts, 0 answers
  1. Sergey Popov
    Sergey Popov avatar
    4 posts
    Member since:
    Dec 2009

    Posted 17 Feb 2013 Link to this post

    Have simple model with RegularExpression attribute. This attribute correct work with unobtrusive validation.

    public class PersonModel
    {
        public int PersonId { get; set; }
        [RegularExpression(@"\+?\d[\d-]+\d")]
        public string Phone { get; set; }
    }

    Render data in Grid. 

    @(Html.Kendo().Grid<PersonModel>().Name("Persons")
        .DataSource(src => src.Ajax()
            .Model(model => model.Id(p => p.PersonId))
            .Read("_GetPersons", "Account")
            .Create("_CreatePerson", "Account")
            .Update("_UpdatePerson", "Account")
            .Destroy("_DestroyPerson", "Account")
            .ServerOperation(true)
        )
        .ToolBar(command => command.Create())
        .Columns(col =>
        {
            col.Bound(p => p.PersonId).Hidden();
            col.Bound(p => p.Phone);
            col.Command(command =>
            {
                command.Edit();
                command.Destroy();
            });
        })
        .Pageable()
        .Editable(e => e.Mode(GridEditMode.PopUp))
    )

    On edit record in popup editor, have javascript error "SyntaxError: invalid quantifier" because in html field render parameter data-val-regex-pattern="+?d[ds-]+d". All backslashes is disappear. 
    ОК, write expression as @"\\+?\\d[\\d-]+\\d". Validation on page is OK, but in action method ModelState.IsValid = false. How can I solve this problem? Code of action method see below.

    [HttpPost]
    public ActionResult _UpdatePerson([DataSourceRequest] DataSourceRequest request, PersonModel model)
    {
        if (model != null && ModelState.IsValid)
        {
            DB.UpdatePerson(model);
        }
        return new JsonNetResult { Data = ModelState.ToDataSourceResult() };
    }

  2. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2289 posts

    Posted 18 Feb 2013 Link to this post

    Hello Sergey,

    Indeed this is known limitation in current Grid implementation. It will be addressed with next official release.

    Regards,
    Nikolay Rusev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top