This is a migrated thread and some comments may be shown as answers.
Remote data annotataion property implementation on Kendo editable Grid Column
3 Answers 18 Views
This is a migrated thread and some comments may be shown as answers.
Aarti
Top achievements
Rank 1
Aarti asked on 26 Mar 2015, 04:30 PM
Hi

I have implemented below custom validation rule. It works but it triggers a controller method twice once on Edit of cell and once Closure of cell. I just wanted it to be triggered on closure of cell. Can you please help me on this. Thank you

My property in in my Model is as below

 [Remote("IsUniqueDisplayName", "Bookmark", AdditionalFields = "DocumentTypeId", ErrorMessage = "Display Name must be Unique.")]
 public string DocumentTypeSortNameTitle { get; set; }

Custom validation rule implementation in javascript as below

 (function ($, kendo) {
        $.extend(true, kendo.ui.validator, {
            rules: {
                mvcremotevalidation: function (input) {
                    if (input.is("[data-val-remote]") && input.val() != "") {
                        var remoteURL = input.attr("data-val-remote-url");
                        var valid = true;
                        var td = input.parent('td');
                        if (td.hasClass("k-dirty-cell")) {
                            var found = false;
                            $.ajax({
                                async: false,
                                url: remoteURL,
                                type: "GET",
                                dataType: "json",
                                data: validationData(input, this.element),
                                success: function (result) {
                                    found = result;
                                    if (found)
                                        valid = false;
                                    else {
                                        valid = true;
                                    }
                                },
                                error: function () {
                                    valid = false;
                                }
                            });
                        }
                       return valid;
                      
                    }

                    return true;
                }
            },
            messages: {
                mvcremotevalidation: function (input) {
                     return input.attr("data-val-remote");
                  //  return "Display Name must be Unique";
                }
            }
        });

        function validationData(input, context) {
            var grid = $("#BookmarkDoctypeGrid").data("kendoGrid");
            var currentData = grid.dataSource.data();
            var uid = $("#BookmarkDoctypeGrid").find('.k-edit-cell').parent('tr').data('uid');
            var dataItem = grid.dataSource.getByUid(uid);
            var documentTypeId = dataItem.DocumentTypeId;
            var fields = input.attr("data-val-remote-additionalFields").split(",");
            var name = input.prop("name");
            var prefix = name.substr(0, name.lastIndexOf(".") + 1);
            var fieldName;
            var data = {};
            for (var i = 0; i < fields.length; i++) {
                fieldName = fields[i].replace("*.", prefix);
                if (fieldName == 'DocumentTypeId') {
                    data[fieldName] = documentTypeId;
                } else
                    {
                    data[fieldName] = $("[name='" + fieldName + "']", context).val();
                }
            }            
            return data;
        }
    })(jQuery, kendo);

3 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 30 Mar 2015, 03:30 PM
Hello Aarti,

I am afraid you cannot change this behavior. The Grid will always trigger the validation two times. Once when the cell loses focus and once when the Update button is clicked.

Kind Regards,
Petur Subev
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Aarti
Top achievements
Rank 1
answered on 30 Mar 2015, 04:55 PM
Hi Petur,

Thanks for your reply. Actually i am not saying that it raises on Update button click .

I have a grid with batch updates and lets say i clicked on of the cell , it goes to editable mode. After updating the old value lets say i click somewhere else on the page, then what I see custom validation event is triggered and editable cell still in edit mode but with no cursor inside it so again i click to next cell to get back from edit mode and this time again it raises custom validation function. So it means when i loose focus on cell(cell looks still in edit mode) and on closure of cell(cell doesnt look in edit mode) it raises twice.
0
Petur Subev
Telerik team
answered on 01 Apr 2015, 01:28 PM
Hello Aarti,

My apologies I did not notice you are using InCell editing mode. The scenario remains the same the validation is triggered once on focus-out event of an input and it is again triggered when the save event of the Grid is triggered (which is when you are about to quit edit mode or when you press update button in popup editing).

Sadly we cannot change this validation behavior it is how the editable component that the Grid is designed to work - it is designed to work for several inputs so you can actually skip focising any of the inputs so before save there is validation triggered. I hope this clarifies the case.

My apologies for any inconvenience caused.

Kind Regards,
Petur Subev
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
Grid
Asked by
Aarti
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Aarti
Top achievements
Rank 1
Share this question
or