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

[Solved] custom grid validation popup message from edit event

5 Answers 404 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Wit
Top achievements
Rank 1
Wit asked on 19 Sep 2014, 09:35 AM
Hi ,

I have tried to use a custom validation on the schema/model/fields but is not quite working for me.
custom: function (input) {
  if (input.is("[name='LogicalName']") && input.val() != "") {
      $http.post("odata/Entities/IsNameUnique", { logicalName: input.val() }).success(function (data, status, headers, config) {
         if (!data.value) {
          input.attr("data-custom-msg", "Name is not unique");
          return false
        }
        return true;
});
                                            }
                                        }

Instead I am trying to use grid edit event which is giving me more flexibility.
Example
dojo.telerik.com/aJeXE

How could I display validation popup message from edit event?

5 Answers, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 22 Sep 2014, 12:42 PM
Hi Wit,

The Grid's edit event could be used to get the instance of the built-in Validator, extend its options with the new validation rules and messages and apply them using the setOptions method. For example: 
function onEdit(e) {
    var validator = e.container.getKendoValidator();
    var options = validator.options;
    var extendedOptions = kendo.deepExtend(options, { rules: { myRule: function (input) { /*....*/ return false; } }, messages: { myRule: "Custom validation message" } });
    validator.setOptions(extendedOptions);
}


Regards,
Alexander Popov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Wit
Top achievements
Rank 1
answered on 22 Sep 2014, 02:12 PM
Hi Alexander,

That looks very promising. I am using typescript in my project and kendo.deepExtend is not recognised. Would you have any suggestions how I could fix it?

Thank you
Wit
0
Accepted
Alexander Popov
Telerik team
answered on 22 Sep 2014, 02:24 PM
Hello again Wit,

Manually extending the options object should also work. For example: 
function onEdit(e) {
    var validator = e.container.getKendoValidator();
    var options = validator.options;
    options.rules.myRule = function(){/*...*/};
    options.messages.myRule = "message";
    validator.setOptions(options);
}


Regards,
Alexander Popov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Wit
Top achievements
Rank 1
answered on 22 Sep 2014, 02:45 PM
Hi Alexander,

Should that prevent me from moving to the next cell when input validation failed? Or should I manually cancel event? 

Thank you
0
Alexander Popov
Telerik team
answered on 24 Sep 2014, 09:16 AM
Hi Wit,

That is correct - if the validation fails the user should not be able to leave the cell.

Regards,
Alexander Popov
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
Wit
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Wit
Top achievements
Rank 1
Share this question
or