[英]On an editable material-table, how can you restrict the user to not be able to enter chars, special characters or negative numbers?
[英]On an cellEditable material-table, how to restrict the user from entering negative number?
我在我的項目中使用可編輯的材料表單元格。 我想限制用戶在該字段中輸入否定的 no。 另外,拋出錯誤驗證。 如何實現?
https://codesandbox.io/s/material-demo-forked-h1f8d?file=/demo.js:609-979
<MaterialTable
title="Cell Editable Preview"
columns={columns}
data={data}
cellEditable={{
onCellEditApproved: (newValue, oldValue, rowData, columnDef) => {
return new Promise((resolve, reject) => {
console.log("newValue: " + newValue);
setTimeout(resolve, 1000);
});
}
}}
/>
Material-table 支持通過列進行驗證。 您必須在列中添加驗證鍵,然后根據您的要求進行驗證。 例如:
columns={[
{
title: 'Name', field: 'name', validate: rowData => rowData.name === '' ? 'Name cannot be empty' : ''
},
]}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.