【问题标题】:jsgrid field "required" inside dialog doesn't work对话框内的jsgrid字段“必需”不起作用
【发布时间】:2016-09-06 08:01:30
【问题描述】:

我想将name: "Name" 的字段设置为required 并根据jsgrid 文档(http://js-grid.com/docs/#grid-fields)插入:validate: "required",但它不起作用。

在我下面的 jsgrid 字段代码中插入 validate: "required" 时:Name jsgrid 没有采取所需的限制并插入块! 我几乎可以肯定,我将网格包含在对话框中这一事实会产生问题,因为 validate 是一个可以在对话框和 jsgrid 中定义的参数。

这是带有对话框的代码,其中我成功地在对话框中显示了我的网格,但我无法通过验证:“必需”。我还上传了截图Grid inside dialog

$( "#DataGrid" ).dialog({minWidth: 1000, minHeight: 500});
            $("#DataGrid").jsGrid({
                    height: "100%",
                    width: "70%",
                    filtering: true,
                    editing: true,
                    inserting: true,
                    sorting: true,
                    paging: true,
                    autoload: true,
                    pageSize: 15,
                    pageButtonCount: 5,
                    datatype: "json",
                    deleteConfirm: "Do you really want to delete the client?",
                    controller: db,
                    fields: [
                        { name: "Id", align: "center", width: 45 },
                        { name: "Name", validate:"required," align: "center", type: "text", width: 45 },
                        { name: "Displayed Name(locale)", align: "center", type: "text", width: 40 },
                        { name: "Data Type", align: "center", type: "select", items: db.dataType, valueField: "Id", textField: "Name", width: 40 },
                        { name: "Initial Value", align: "center", type: "text", width: 40 },
                        { name: "Initial State", align: "center", type: "select", items: db.initialState, valueField: "Id", textField: "Name", width: 50 },
                        { name: "Worklist Order", align: "center", type: "number", width: 20 },
                        { name: "DB Datatype", align: "center", type: "text", width: 25 },
                        { name: "Allowed Values JSON", align: "center", type: "text", width: 20 },
                        { name: "Allowed Values SQL", align: "center", type: "text", width: 20 },
                        { type: "control", width: 25 }
                    ]

            });

我尝试了没有对话框的 jsgrid 代码,它可以工作,但它如何在对话框中工作? 这段没有对话框的代码有效:

 $("#DataGrid").jsGrid({
                height: "100%",
                width: "70%",
                filtering: true,
                editing: true,
                inserting: true,
                sorting: true,
                paging: true,
                autoload: true,
                pageSize: 15,
                pageButtonCount: 5,
                datatype: "json",
                deleteConfirm: "Do you really want to delete the client?",
                controller: db,
                fields: [
                    { name: "Id", align: "center", width: 45 },
                    { name: "Name", validate:"required", align: "center", type: "text", width: 45 },
                    { name: "Displayed Name(locale)", align: "center", type: "text", width: 40 },
                    { name: "Data Type", align: "center", type: "select", items: db.dataType, valueField: "Id", textField: "Name", width: 40 },
                    { name: "Initial Value", align: "center", type: "text", width: 40 },
                    { name: "Initial State", align: "center", type: "select", items: db.initialState, valueField: "Id", textField: "Name", width: 50 },
                    { name: "Worklist Order", align: "center", type: "number", width: 20 },
                    { name: "DB Datatype", align: "center", type: "text", width: 25 },
                    { name: "Allowed Values JSON", align: "center", type: "text", width: 20 },
                    { name: "Allowed Values SQL", align: "center", type: "text", width: 20 },
                    { type: "control", width: 25 }
                ]

        });

有什么想法吗?这是一个复杂的问题。

【问题讨论】:

  • 您是否要在对话框中显示网格?尝试用另一个 div 包装网格并在此包装器上初始化对话框。
  • @tabalin 我真的指望你。请听:1)当我的网格和我的对话框都包含在同一个 div 中时,我的网格成功显示在对话框中,但我无法通过(验证:“必需”)从那时起我的网格插入操作块。2)当我将我的网格和对话框包装在不同的网格中,只显示一个空对话框。请问我该怎么办?
  • 我还上传了一个屏幕截图,其中我向您展示了我的网格在我的对话框中的显示方式i.stack.imgur.com/yLViN.png。请记住,在 validate:"required" 之后插入块
  • 你用的是什么版本的js-grid?尝试遵循 js-grid.com/demos Validation 演示中的基本示例,以确保验证适用于您环境中的基本场景。
  • 问题已解决。我做了一个简单的函数: validate: { message: "My message", validator: function(message) { return message; } },

标签: javascript validation dialog field jsgrid


【解决方案1】:

好的,感谢@tabalin 的帮助,我解决了这个问题。我少了一个 jsgrid 存档。现在它就像一个魅力!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-06
    • 2020-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多