如何在IgGrid细胞中获得正则表达(Infragistics)? [英] How to get Regular Expression in IgGrid cell (Infragistics)?
问题描述
如何在igGrid更新中的igTextEditor上使用正则表达式?
how can i have a regular expression on a igTextEditor in igGrid Updating?
我尝试使用验证选项,但它没有用。
i tried to use validate option but it didn't worked.
$("#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的列。
如果您点击添加网格,您可以在输入字段中单击并填写您的时间。在点击完成之前应该验证时间并显示错误消息。
i want to achive a time picker in the Time Column but that doesn't exist so i try to get only time in the textEditor by regular expression. the grid gets loaded with columns named Time, Mo- Friday. if you click on add in grid you can click in the input field and fill your time. the time should get validated before clicking on done and show a error message.
查看表格如何: https://codepen.io/ablablabla/pen/PJLbJz
推荐答案
缺乏验证是因为 validatorOptions
属于 editorOptions
(因为那些传递给您选择作为提供者的任何编辑器)。 validation:true
只会获得一些默认值,除了必需的文本字段外,这对于文本字段确实不会做太多。
The lack of validation is because the validatorOptions
belong to the editorOptions
(as those get passed down to whatever editor you choose as provider). The validation: true
only gets some defaults, which really won't do much for a text field besides the required.
然后RegExp选项(就我所知的上述代码段中的电子邮件而言)已经 模式
从15.2开始:)所以在那个时间列的最后你可以尝试:
And then the RegExp option (which is for an email in the snippet above as far as I can tell) has been pattern
since 15.2 :) So in the end for that time column you can try:
//...
editorOptions: {
validatorOptions: {
pattern: /^\d{1,2}\:\d{2}$/,
onblur: true,
onchange: true
},
},
//..
这是一个更新的代码集: https://codepen.io/anon/pen/YrgYxj
Here's an updated codepen: https://codepen.io/anon/pen/YrgYxj
编辑:或者如果你想要设置错误消息:
Or if you want to set the error message:
//...
editorOptions: {
validatorOptions: {
pattern: {
expression: /^\d{1,2}\:\d{2}$/,
errorMessage: "Time should match a pattern like 00:00"
},
onblur: true,
onchange: true
},
},
//..
根据您的目标,您还可以使用 Mask Editor 或日期编辑器作为提供者。强制性文档链接: https://www.igniteui.com/help/iggrid-updating
Depending on your goals you could also use a Mask Editor or a Date Editor as provider. Also the obligatory docs link: https://www.igniteui.com/help/iggrid-updating
PS绑定到一个空数组,以避免第一行没有值,更重要的是主键的错误。
P.S. Bind to an empty array to avoid the error for that first row that has no values and more importantly primary key.
这篇关于如何在IgGrid细胞中获得正则表达(Infragistics)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!