This is a migrated thread and some comments may be shown as answers.

Incorrect generate validator for model with RegularExpression attribute

1 Answer 59 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sergey Popov
Top achievements
Rank 1
Sergey Popov asked on 17 Feb 2013, 09:54 PM
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() };
}

1 Answer, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 18 Feb 2013, 04:33 PM
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!
Tags
Grid
Asked by
Sergey Popov
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Share this question
or