Want to costomized validation

1 Answer 14 Views
Grid Upload
Pradumn
Top achievements
Rank 1
Pradumn asked on 16 Feb 2024, 10:34 AM
I want to costomised validation, but right now it is showing incorrect validation , I am providing the screen sort and working code. pls provide the correct code so I can costomised the validation.

our working code is:
  $("#EnterpriseNote-grid").kendoGrid({
                                            dataSource: {
                                                type: "json",
                                                transport: {
                                                    read: {
                                                        url: "@Html.Raw(Url.Action("ListEnterpriseNoteData", "Enterprise", new { Id = ViewBag.EnterpriseID }))",
                                                        type: "POST",
                                                        dataType: "json",
                                                        //     data: additionalData
                                                    }, create: {

                                                        url: "@Html.Raw(Url.Action("AddEntrpriseNoteData", "Enterprise", new { newdata = "", Id = ViewBag.EnterpriseID }))",
                                                        type: "GET",
                                                        dataType: "json",
                                                        //  data: addAntiForgeryToken
                                                    },update: {
                                                        url: "@Html.Raw(Url.Action("EditEnterpriseNote", "Enterprise"))",
                                                        type: "POST",
                                                        dataType: "json",
                                                        //   data: addAntiForgeryToken
                                                    },
                                                    destroy: {
                                                        url: "@Html.Raw(Url.Action("DeleteEnterpriseNote", "Enterprise"))",
                                                        type: "POST",
                                                        dataType: "json",
                                                        //   data: addAntiForgeryToken
                                                    },
                                                },
                                                schema: {
                                                    data: "Data",
                                                    total: "Total",
                                                    errors: "Errors",
                                                    model: {
                                                        id: "Id",
                                                        fields: {
                                                            strNoteText: {
                                                                editable: true, type: "string",

                                                                validation: {
                                                                    required: {
                                                                        message: 'Note Text is required'
                                                                    },
                                                                }
                                                            },
                                                            strNextReminderDate : { editable: true, type: "date" },
                                                            strFirstname: { editable: false, type: "string" },
                                                            strAssignedTo: {
                                                                editable: true, type: "string",
                                                                validation: {
                                                                    required: {
                                                                        message: 'PhoneNumber is required'
                                                                    },
                                                                    Assignedvalidation: function (input) {
                                                                        var trimmedValue = input.val().trim();
                                                                        debugger
                                                                        if (input.val() == "") {
                                                                            var acv = $(".k-tooltip-validation[data-for='strAssignedTo']");
                                                                            acv.text("PhoneNumber is required");

                                                                        }
                                                                        return true;
                                                                    },
                                                                }, },
                                                            bitClosedYN: { type: "boolean", editable: true, }
                                                        }
                                                    },
                                                    sort: [{ field: "id", dir: "desc" }]
                                                },
                                                requestEnd: function (e) {
                                                    if (e.type == "create" || e.type == "update") {
                                                        this.read();
                                                    }
                                                },
                                                error: function (e) {
                                                    //display_kendoui_grid_error(e);
                                                    // Cancel the changes

                                                    $('#divError').html('<div class="alert alert-danger alert-dismissable">'
                                                        + '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>Note cannot be deleted because it is being used.'
                                                        + '</div>');
                                                    this.cancelChanges();
                                                },
                                                pageSize: 4,
                                                serverPaging: true,
                                                serverFiltering: true,
                                                serverSorting: true
                                            },
                                            pageable: {
                                                refresh: true,
                                                pageSizes: [10, 15, 20, 50, 100]

                                            },
                                           toolbar: [{ name: "create", text: "Add New" }],
                                            editable: {
                                                confirmation: "Are you sure you want to delete this item?",
                                                mode: "inline",
                                                //mode: "incell"
                                            },
                                            scrollable: false,                                           
                                             ///////////////////////////code by puja verma//////////////////////
                                            dataBound: function (e) {
                                                
                                                var dataItems = this.dataSource.view();
                                                var isFieldPending = false;
                                                var validationErrors = [];
                                                for (var i = 0; i < dataItems.length; i++) {
                                                    if (dataItems[i].strNoteText === "") {
                                                        isFieldPending = true;
                                                        validationErrors.push("Please Save the new record before clicking Next");
                                                        break;

                                                    }
                                                }
                                               
                                                @*////////////////////code by puja verma///////////////////*@
                                                var nextButton = $("#nexttocomplete");
                                                var validationMessage = $("#validationMessageEnterprisenotes1,#validationMessageEnterprisenotes");
                                                if (isFieldPending || validationErrors.length > 0) {
                                                    nextButton.prop("disabled", true);
                                                    validationMessage.text(validationErrors.join('\n'));

                                                }
                                                
                                                else {
                                                    nextButton.prop("disabled", false);
                                                    validationMessage.text("");
                                                }
                                            },
                                              ///////////////////////////code by puja verma//////////////////////
                                            // dataBound: onDataBound,
                                            columns: [

                                                {
                                                    title: "Action",
                                                    command: [
                                                        {
                                                            name: "edit",
                                                            text: {
                                                                edit: '<i style="color:#B60202;" class="fa fa-edit fa-lg"></i>',
                                                                update: '<i style="color:#B60202;" class="fa fa-floppy-o" aria- hidden="true"></i>',
                                                                cancel: '<i style="color:#B60202;" class="fa fa-close fa-lg"></i>'
                                                            }
                                                        },

                                                        {
                                                            name: "destroy",
                                                            text: '<i style="color:#B60202;" class="fa fa-trash fa-lg"></i>'
                                                        }
                                                    ],
                                                    width: 130
                                                },

                                                {
                                                    field: "strNoteText",
                                                    title: "Enterprise Note",
                                                    width: 300
                                                },
                                                {
                                                    field: "strAssignedTo",
                                                    title: "Assigned to",
                                                    width: 300,
                                                    template: '#=strFirstname#',
                                                    editor: function (container, options) {
                                                        $('<input required name="' + options.field + '"/>')
                                                            .appendTo(container)
                                                            .kendoDropDownList({
                                                                dataSource: noteList,
                                                                dataTextField: "strFirstname",
                                                                dataValueField: "strAssignedTo",
                                                                valuePrimitive: true,
                                                                autoBind: false,
                                                                optionLabel: "Select site admin",
                                                                height: 500
                                                            })
                                                    },
                                                },
                                                {
                                                    field: "strNextReminderDate",
                                                    title: "Reminder Date",
                                                    format: "{0:dd/MM/yyyy}",
                                                    width: 300
                                                },
                                                {
                                                    field: "bitClosedYN",
                                                    title: "Status",
                                                    width: 100,
                                                    //template: "<input type='checkbox' name='bitClosedYN' checked='checked' disabled='disabled' />",
                                                    template: "#= (bitClosedYN == true ) ? 'Yes' : 'No' #",
                                                    attributes: { class: "ob-fld-boolean" },
                                                }

                                                    ]
                                                });

1 Answer, 1 is accepted

Sort by
0
Neli
Telerik team
answered on 21 Feb 2024, 07:19 AM

Hi Pradumn,

Could you please provide more details about the expected result as I am not sure I understand the issue correctly? Do you need to change the message when the validation error appears? Linked here you will find a Dojo example where a custom validation for the ProductName column is demonstrated. In the example, the product name should start with a capital letter. Could you please use the example and modify it in order to replicate the issue the way it is on your side and send it back, so we could get a better idea of the exact scenario?

Looking forward to your reply.

Regards,
Neli
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Kendo family, check out our getting started resources
Tags
Grid Upload
Asked by
Pradumn
Top achievements
Rank 1
Answers by
Neli
Telerik team
Share this question
or