2

如何在 igGrid 更新中的 igTextEditor 上使用正则表达式?

我尝试使用验证选项,但没有奏效。

   $("#schedulerTable").igGrid({
            columns: $scope.schedulerColumns,
            width: "87%",
            height: "300px",
            fixedHeaders: true,
            autoGenerateColumns: false,
            autofitLastColumn: true,
            autoCommit: true,
            renderCheckboxes: true,
            responseDataKey: "results",
            dataSource: $scope.schedulerData,
            updateUrl: "",
            primaryKey: 'Id',
            features: [
            {
                name: "Updating",
                generatePrimaryKeyValue: function (evt, ui) {
                    nextPrimarykey -= 1;
                    ui.value = nextPrimarykey;
                },
                enableAddRow: true,
                enableDeleteRow: true,
                editMode: "row",
                columnSettings: [
                   {
                       columnKey: "Id",
                       editorType: "numeric",
                       editorOptions: {
                           readOnly: true
                       }
                   }, {
                       columnKey: "Time",
                       editorType: "text",

                       editorOptions: {
                       },
                       validatorOptions: {
                           regExp: /^[a-zA-Z]{1}[a-zA-Z0-9_\.\-]*\@\w{2,10}\.\w{1,10}$/,
                           onblur: true,
                           onchange: true
                       },

                       required: true,
                       validation: true,
                       defaultValue: "00:00"
                   },
                   {
                       columnKey: "Mo"

                   },
                   {
                       columnKey: "Tu"

                   },
                    {
                        columnKey: "We"

                    },
                    {
                        columnKey: "Th"

                    },
                    {
                        columnKey: "Fi"

                    }]
            }]
        });

我想在时间列中获得一个时间选择器,但它不存在,所以我尝试通过正则表达式在 textEditor 中只获取时间。网格加载了名为 Time, Mo-Friday 的列。如果您单击添加网格,您可以单击输入字段并填写您的时间。在单击完成之前应该验证时间并显示错误消息。

查看表格的外观:https ://codepen.io/ablablabla/pen/PJLbJz

4

1 回答 1

3

缺乏验证是因为validatorOptions属于editorOptions(因为那些被传递给您选择作为提供者的任何编辑器)。唯一的validation: true获得一些默认值,除了必需的文本字段之外,这实际上不会做太多事情。

然后 RegExp 选项(据我所知,这是上面片段中的电子邮件)pattern从 15.2 开始 :) 所以最后对于那个时间列,你可以尝试:

//...
    editorOptions: {
     validatorOptions: {
       pattern: /^\d{1,2}\:\d{2}$/,
       onblur: true,
       onchange: true
     },
    },
//..

这是一个更新的代码笔: https ://codepen.io/anon/pen/YrgYxj

编辑:或者如果你想设置错误信息:

//...
    editorOptions: {
     validatorOptions: {
       pattern: {
        expression: /^\d{1,2}\:\d{2}$/,
        errorMessage: "Time should match a pattern like 00:00"
       },
       onblur: true,
       onchange: true
     },
    },
//..

根据您的目标,您还可以使用掩码编辑器日期编辑器作为提供者。还有强制性文档链接:https ://www.igniteui.com/help/iggrid-updating

PS 绑定到一个空数组以避免第一行没有值,更重要的是主键的错误。

于 2017-10-20T14:56:52.377 回答