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

Grid Popup Validation with AngularJS

1 Answer 168 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Christoph asked on 23 Sep 2015, 03:43 PM


i cant find the best way to validate dependent fields within the popup dialog from Kendo.

Here are my grid options:


$scope.gridOptions = {
    dataSource: data,
    selectable: "row",
    language : $translate.use(),
    pageable: true,
    editable: {
        mode: "popup",
        template: kendo.template($("#orderEditTemplate").html())
    save: function(e) {
        if(e.model.OrderStateId == 9) {
            if(!e.model.ErrorReason) {
                $scope.error = "Reason!!!";
    columns: [
            field: "CreatedOn",
            title: $translate.instant("ADMIN.ORDERS.GRID.CREATEDON"),
            template: "#= moment(CreatedOn).format('L LT') #"
            field : 'TotalAmount',
            template : "{{ dataItem.TotalAmount | ccurrency:dataItem.Currency }}",
            title: $translate.instant("ADMIN.ORDERS.GRID.TOTALAMOUNT")
            field: "Description",
            title: $translate.instant("ADMIN.ORDERS.GRID.DESCRIPTION")
            field: "OrderStateId",
            title: $translate.instant("ADMIN.ORDERS.GRID.STATUS"),
            template : '{{ dataItem.OrderStateId | orderStatus }}'
            command: "edit",
            title: " ",
            width: "100px"

 This is my Popup Template:

<script type="text/x-kendo-template" id="orderEditTemplate">
        <div class="alert alert-danger" ng-show="error">
        <div class="form-group">
            <select kendo-drop-down-list k-on-change="dataItem.dirty=true" k-data-text-field="'Text'" k-data-value-field="'Value'" k-data-source="orderStates" ng-model="dataItem.OrderStateId"></select>
        <div class="form-group" ng-show="dataItem.OrderStateId == 9">
            <textarea class="form-control" rows="3" ng-model="dataItem.ErrorReason"></textarea>


What i woud like to to is. If the OrderStateId is set to 9, the ErrorReason field is required. If the OrderStateId is set the anything else, your good to go without ErrorReason. My Problem ist that my error-Alert in the Popup is never going to be displayed. I don't know why, but could it be possible that inside the popup its a different scope?

 What is the best way with Kendo and Angular to Validate such things?


Best Regards


1 Answer, 1 is accepted

Sort by
Vladimir Iliev
Telerik team
answered on 28 Sep 2015, 07:51 AM
Hi Christoph,

This can be done by either setting custom validation rules in the dataSource "schema.model.fields.field.valdation" option or by extending the grid build-in validation rules. The demo for the first approach is available in the linked help article. For the second approach (extending the grid build-in validation rules) you can check the following example:

//the code should be placed before the grid is initialized
function ($, kendo) {
    //Extending the build in validator
    $.extend(true, kendo.ui.validator, {
        rules: {
            // custom rules
            custom: function (input, params) {
                //check if current input is the needed one as the
                //custom rules are executed against all editors in the edit form
                if ("#LastSupply")) {
                    var datePicker = $(input).data("kendoDatePicker");
                    var max = datePicker.max();
                    var min = datePicker.min();
                    var currentInputDate = new Date(input.val());
                    if (min > currentInputDate || max < currentInputDate) {
                        //return false to signify validation error
                        return false;
                //return true to signify validation success
                return true;
        messages: {
            //custom rules messages
            custom: function (input) {
                // return the message text
                return "Date out of range!";
})(jQuery, kendo);

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