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

[Solved] Remote validation in inline add mode

3 Answers 236 Views
Grid
This is a migrated thread and some comments may be shown as answers.
prakash
Top achievements
Rank 1
prakash asked on 24 Feb 2015, 02:51 PM
Following is my kendo grid

@section scripts{
@Scripts.Render("~/bundles/jqueryval")
}

 @(Html.Kendo().Grid<Category>()
          .Name("grid")
          .Columns(columns =>
          {             columns.Bound(c => c.Id);    
              columns.Bound(c => c.Name)
                .ClientTemplate("<a href='" + Url.Action("Edit", "category") + "/#= Id #' " + ">#= Name #</a>").Width(140)
                .Filterable(ftb => ftb.Cell(cell => cell.ShowOperators(true)));

              columns.Bound(c => c.Color).Width(80).Filterable(false).Sortable(false).ClientTemplate("<div style='width: 25px; height: 25px; background: #=Color#;'></div>");

              columns.Bound(r => r.AltName).Width(240);

          
              columns.Command(command => { command.Edit(); }).Width(150);
          })
                   .Events(e => e.Edit("grid_edit"))
                .ToolBar(toolbar => toolbar.Create())
                .Editable(editable => editable.Mode(GridEditMode.InLine))
                .EnableCustomBinding(true)
                .HtmlAttributes(new { style = "height: 380px;" })
                .Filterable(ftb => ftb.Mode(GridFilterMode.Row))
                .Scrollable()
                .Sortable()
                .Pageable(pageable => pageable
                .Refresh(true)
                .PageSizes(true)
                .ButtonCount(5))
                .DataSource(dataSource => dataSource
                .Ajax().Read(read => read.Action("Get", "Person"))
                .Update(update => update.Action("SaveOrUpdate", "Person"))
                .Create(update => update.Action("SaveOrUpdate", "Person"))
               .Model(model =>
              {
                  model.Id(p => p.Id);
                  model.Field(p => p.Color).DefaultValue("#000000");
                  model.Field(p => p.Id).DefaultValue(new Guid());
                  model.Field(p => p.TenantId).DefaultValue(new Guid());
                  model.Field(p => p.RowVersion);
              })

                )
    )

Following is my viewmodel

public class Person
    {


        [Required]
        [Remote("IsPersonUnique", "Validation", "Admin" , AdditionalFields = "Id")]
        public string Name { get; set; }

        [UIHint("CategoryColorPicker")]
        public string Color { get; set; }

        public string AltName { get; set; }

    }

And my remote validation action method

public JsonResult IsPersonUnique(string name, Guid id)
        {
            return CategoryService.IsPersonUnique(name, id)
                ? Json(true, JsonRequestBehavior.AllowGet)
                : Json(false, JsonRequestBehavior.AllowGet);
        }

Now the remote validation doesn't fire when I am adding items inline in grid.
But it works fine when I add it through another detail page, for the same model.

But the required field validations work fine. 



3 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 26 Feb 2015, 11:02 AM
Hi Prakash,

Currently the "Remote" validation attribute is not supported out of the box, however there is such idea posted in our UserVoice portal (you can vote for it). Most voted ideas are included in next Kendo UI releases. 

Also for convenience I created small example which demonstrates how to add support for "Remote" validation attribute and attached it to the current thread.

Regards,
Vladimir Iliev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Mark
Top achievements
Rank 1
answered on 09 Apr 2015, 03:32 PM

Hi Vladimir,

Looking at your workaround I can see that you use an ajax call with async set to false. 

This is problematic as the whole UI will freeze until the call returns (not good!! especially if there's a problem and the call takes longer than expected) . 

Can you let us know when 'exactly' remote validation will be added to kendo.

Kindest Regards Mark

0
Kiril Nikolov
Telerik team
answered on 14 Apr 2015, 07:32 AM

Hello Mark,

I am afraid that this is the only way to implement this functionality. As the response from the ajax call is needed in order to proceed with the validation. Currently we do not have any other solution for the given problem.

Thanks for the understanding.

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
prakash
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Mark
Top achievements
Rank 1
Kiril Nikolov
Telerik team
Share this question
or