单元格验证
您可以在高级栅格和高级树形栅格中验证单元格。单元格验证对于在编辑过程中避免栅格中输入任何无效条目而言非常重要。通过单元格验证,您可以显示验证错误,并在工具提示中提供错误更正消息。您可以使用 ValidationErrorCellStyleValidationErrorTooltipStyle 属性在 Mashup Builder 配置中显示验证错误。您也可以使用 JSON 配置进行单元格验证。
使用 ValidationErrorCellStyle 属性以在出现验证错误时对单元格进行样式设置。此样式将取代已为单元格配置的任何其他样式。
使用 ValidationErrorTooltipStyle 属性以在出现验证错误时对工具提示进行样式设置。
仅可在 JSON 中配置验证错误消息。此外,可通过仅在 JSON 配置中提供 l8n 标记来本地化验证消息。
验证失败时,已配置的错误消息会显示在单元格的工具提示中,并且单元格边框将根据错误类型显示为红色或黄色。
存在两种类型的验证错误:
阻止错误:这些是警告错误。例如,id 列中的错误或已使用 NotEmpty 验证器配置的空单元格中的错误。在解决这些错误之前,您无法保存编辑内容。默认情况下,此类错误将以红色边界突出显示。
非阻止错误:这些不是关键错误,例如,配置为整数的单元格中的字符串值条目。在解决这些错误之前,您可以保存所做的编辑。默认情况下,此类错误以黄色边界突出显示。
如需查看两种错误之间的差异,请参阅以下示例。
* 
在主键列上使用单元格验证对于避免任何服务器错误或例外非常重要。将使用 IDFieldName 属性来分配主键列。通常,主键列为 id 列。
添加以下内容可启用单元格验证并定义验证错误样式和工具提示样式。
"cellEditor": { // optional: defines cell-editing options for this column
"enabled": true, // *{boolean} to indicate whether cell editing is enable for this column
"validator": { // optional: when defined will validate input values against the chosen validator types and error and success messages will be displayed.
"types": ['NotEmpty'], // {Array} optional: defines list of validator types, e.g. 'NotEmpty', 'ValidURL' or 'Custom'.
"errorMessage": "[[invalidNumberNotEmpty]]", // *{string} localization token name of the error message.
"errorStyle": "cellValidationErrorStyle" // *{string} style definition name of the error message. }
}
"cellValidationErrorStyle": {
"backgroundColor": "",
"secondaryBackgroundColor": "",
"foregroundColor": "black",
"textDecoration": "none",
"image": "",
"lineColor": "red",
"borderStyle": "solid",
"borderWidth": "1px",
"fontFamily": ["helvetica", "arial"],
"fontStyle": "normal",
"fontSize": "11px",
"fontWeight": "normal"
},
"cellValidationErrorTooltipStyle": {
"backgroundColor": "red",
"secondaryBackgroundColor": "",
"foregroundColor": "white",
"textDecoration": "none",
"image": "",
"lineColor": "white",
"borderStyle": "solid",
"borderWidth": "1px",
"fontFamily": ["helvetica", "arial"],
"fontStyle": "normal",
"fontSize": "11px",
"fontWeight": "normal"
},
"tooltipStyle": {
"backgroundColor": "#0000ff",
"secondaryBackgroundColor": "",
"foregroundColor": "#ffffff",
"textDecoration": "",
"image": "",
"lineColor": "",
"borderStyle": "none",
"borderWidth": "",
"fontFamily": ["helvetica", "arial"],
"fontStyle": "normal",
"fontSize": "12px",
"fontWeight": ""
},
验证操作适用于每种呈现器类型。您可以根据列呈现器类型在 JSON 配置中指定验证器。以下验证器适用于每一种呈现器类型:
呈现器
验证器
string
<None>, NotEmpty, ValidURL
integer
<None>, NotEmpty, (ValidInteger is default)
long
<None>, NotEmpty, (ValidNumeric is default)
number
<None>, NotEmpty, (ValidNumeric is default)
boolean
<None>, NotEmpty, (ValidBoolean is default)
location
<None>, NotEmpty, (ValidLocation is default)
html
<None>, NotEmpty
imagelink
<None>, NotEmpty
hyperlink
<None>, NotEmpty, ValidURL
datetime
<None>, NotEmpty, (ValidDatetime is default)