【问题标题】:Kendo Grid Date format validation not working剑道网格日期格式验证不起作用
【发布时间】:2023-03-03 18:18:01
【问题描述】:

为什么当我输入无效格式时只显示字段名称。即使我尝试了不同的验证样式,它仍然会显示格式是否无效。我已经创建了自定义验证,但它仅在日期为空或 null 时才有效,但如果不是,则它不起作用,这是因为当我在字段中输入错误格式时,自定义验证不起作用。

image of the actual validation

这里是代码

$('#lot-sched-grid').kendoGrid({
        dataSource: new kendo.data.DataSource({
            transport: {
                read: {
                    url: "maintenance/sales/s-lot-sched/read-header/0",
                    dataType: "json"
                },              
                update: {
                    url: "maintenance/sales/s-lot-sched/update",
                    type: "POST",
                    dataType: "json",
                    complete: function(jqXhr, textStatus) {
                        if (textStatus == 'success') {
                            /*var grid = vm.GRID.init();
                            grid.dataSource.read();*/
                            vm.GRID.init().dataSource.read();
                            
                            swal("Success", "Lot Remarks is successfully updated!", "success");
                        } else {
                            vm.error(jqXhr);
                        }
                    }
                }
            
            },
            pageSize: window.uiDefaults.pageSize,
            // batch: true,
            schema: {
                model: {
                    id: "lot_id",
                    fields: {
                        lot_id: { editable: false, nullable: true },
                        lot_prod_grp_id: { type: "string" },
                        lot_year: { type: "string", editable: false },
                        lot_code: { type: "string", editable: false },
                        lot_start_date: { 
                            type: "date", 
                            parse: function(value) {
                                return kendo.toString(value, "yyyy-MM-dd");
                            },
                            validation: {
                                custom: function(input) {
                                    if (input.is("[name='lot_start_date']") && input.val().length == 0) {
                                        input.attr("data-custom-msg", "Start date is required.");
                                        return false;
                                    }

                                    return true;
                                }
                            }
                        },
                        lot_remarks: { 
                            type: "string",
                            validation: {
                                lotremarks_min_validate: function (input) {
                                    if (input.is("[name='lot_remarks']") && input.val().length < 4 && input.val().length != 0) {
                                        input.attr("data-lotremarks_min_validate-msg", "Lot Remarks minimum input value is 4.");
                                        return false;
                                    }
                                    return true;
                                },
                                lotremarks_max_validate: function (input) {
                                    if (input.is("[name='lot_remarks']") && input.val().length > 100 && input.val().length != 0 ) {
                                        input.attr("data-lotremarks_max_validate-msg", "Lot Remarks maximum input value is 100.");
                                        return false;
                                    }
                                    return true;
                                },
                            },

                        },
                    }
                }
            }
        }),
        scrollable: false,
        filterable: window.uiDefaults.filterable,
        pageable: window.uiDefaults.pageable,
        sortable: window.uiDefaults.sortable,
        noRecords: true,
        messages: {
            noRecords: window.uiDefaults.noRecordsMessage,
        },
        selectable: "row",
        /*save: function(e){
            console.log(e);
        },*/
        editable: true,
        toolbar: [ 'save', 'cancel' ],
        columns: [      
        {
            field: "lot_code",
            title: "Lot Code",
            width: 120,
        },
        {
            field: "lot_year",
            title: "Year",
            width: 100,
        },
        {
            field: "lot_start_date",
            title: "Start Date",
            format: "{0:yyyy-MM-dd}",
            width: 120,
        },
        {
            field: "lot_remarks",
            title: "Remarks",
            template: kendo.template($('#lot-remarks-template').html()),
        }],
    });

【问题讨论】:

    标签: php laravel kendo-ui kendo-grid


    【解决方案1】:

    尝试更改您要添加的属性名称。

    更改以下内容:

    input.attr("data-custom-msg", "Start date is required.");
    

    收件人:

    input.attr("data-lot_start_date-msg", "Start date is required.");
    
    

    【讨论】:

      【解决方案2】:

      所以我所做的就是将自定义验证更改为日期验证,并在验证内创建一个条件以确定它是否为空以及是否有不正确的格式。

      【讨论】:

        猜你喜欢
        • 2019-07-11
        • 1970-01-01
        • 1970-01-01
        • 2013-07-08
        • 1970-01-01
        • 2018-01-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多