儲存格驗證
您可在「進階網格」與「進階樹網格」中驗證儲存格。必須進行儲存格驗證,才能避免在編輯時在網格中出現任何無效項目。您可透過儲存格驗證顯示驗證錯誤,並在工具提示中提供錯誤修正訊息。您可使用 ValidationErrorCellStyleValidationErrorTooltipStyle 內容在 Mashup Builder 組態中顯示驗證錯誤。您也可以使用 JSON 組態進行儲存格驗證。
使用 ValidationErrorCellStyle 內容可在發生驗證錯誤時為儲存格設定樣式。此樣式會取代已針對儲存格配置的其他任何樣式。
使用 ValidationErrorTooltipStyle 內容可在發生驗證錯誤時為工具提示設定樣式。
您可使用 JSON 或使用小器具組態對話方塊來配置驗證運算式與錯誤訊息。欲當地語系化錯誤訊息,請使用當地語系化權杖。
若驗證失敗,配置的錯誤訊息會顯示在儲存格的工具提示中,且儲存格邊框會加上紅色或黃色框線,具體視錯誤類型而定。
有兩種類型的驗證錯誤:
封鎖錯誤:這些錯誤是警告錯誤。例如,id 欄中的錯誤,或使用 "NotEmpty" 驗證器配置的空白儲存格中的錯誤。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 組態中指定驗證器。下列驗證器可用於每種轉譯器類型:
轉譯器
驗證器
字串
<None>, NotEmpty, ValidURL
整數
<None>, NotEmpty, (ValidInteger is default)
long
<None>, NotEmpty, (ValidNumeric is default)
number
<None>, NotEmpty, (ValidNumeric is default)
布林值
<None>, NotEmpty, (ValidBoolean is default)
location
<None>, NotEmpty, (ValidLocation is default)
html
<None>, NotEmpty
imagelink
<None>, NotEmpty
超連結
<None>, NotEmpty, ValidURL
datetime
<None>, NotEmpty, (ValidDatetime is default)
這是否有幫助?