-
Notifications
You must be signed in to change notification settings - Fork 0
/
cfacc208.1c53e823.js
1 lines (1 loc) · 7.43 KB
/
cfacc208.1c53e823.js
1
(window.webpackJsonp=window.webpackJsonp||[]).push([[70],{144:function(e,t,n){"use strict";n.r(t),n.d(t,"frontMatter",(function(){return i})),n.d(t,"metadata",(function(){return l})),n.d(t,"toc",(function(){return o})),n.d(t,"default",(function(){return b}));var a=n(3),r=(n(0),n(165));n(179);const i={id:"basic",title:"Cell Validation"},l={unversionedId:"validation/basic",id:"validation/basic",isDocsHomePage:!1,title:"Cell Validation",description:"material-table-core supports cell validation during edit.",source:"@site/demos/validation/basic.mdx",slug:"/validation/basic",permalink:"/demos/validation/basic",version:"current",sidebar:"sidebar",previous:{title:"Basic Tree Data",permalink:"/demos/tree-data/basic"},next:{title:"Summary Row",permalink:"/demos/Summaryrow/basic"}},o=[{value:"Following returns are supported:",id:"following-returns-are-supported",children:[]},{value:"Examples",id:"examples",children:[]}],c={toc:o};function b(e){let{components:t,...n}=e;return Object(r.b)("wrapper",Object(a.a)({},c,n,{components:t,mdxType:"MDXLayout"}),Object(r.b)("p",null,"material-table-core supports cell validation during edit."),Object(r.b)("table",null,Object(r.b)("thead",{parentName:"table"},Object(r.b)("tr",{parentName:"thead"},Object(r.b)("th",{parentName:"tr",align:null},"Field"),Object(r.b)("th",{parentName:"tr",align:null},"Type"),Object(r.b)("th",{parentName:"tr",align:null}))),Object(r.b)("tbody",{parentName:"table"},Object(r.b)("tr",{parentName:"tbody"},Object(r.b)("td",{parentName:"tr",align:null},Object(r.b)("inlineCode",{parentName:"td"},"column.validate")),Object(r.b)("td",{parentName:"tr",align:null},"func"),Object(r.b)("td",{parentName:"tr",align:null},"The function to validate the current cell")))),Object(r.b)("h3",{id:"following-returns-are-supported"},"Following returns are supported:"),Object(r.b)("table",null,Object(r.b)("thead",{parentName:"table"},Object(r.b)("tr",{parentName:"thead"},Object(r.b)("th",{parentName:"tr",align:"center"},"Return value"),Object(r.b)("th",{parentName:"tr",align:"center"},"Type"),Object(r.b)("th",{parentName:"tr",align:null}))),Object(r.b)("tbody",{parentName:"table"},Object(r.b)("tr",{parentName:"tbody"},Object(r.b)("td",{parentName:"tr",align:"center"},Object(r.b)("inlineCode",{parentName:"td"},"boolean")),Object(r.b)("td",{parentName:"tr",align:"center"},"rowData => boolean"),Object(r.b)("td",{parentName:"tr",align:null},"Return a Boolean to block save and show a red bar below that field (true for valid input)")),Object(r.b)("tr",{parentName:"tbody"},Object(r.b)("td",{parentName:"tr",align:"center"},Object(r.b)("inlineCode",{parentName:"td"},"string")),Object(r.b)("td",{parentName:"tr",align:"center"},"rowData => string"),Object(r.b)("td",{parentName:"tr",align:null},"Return a string to block save, to show a red bar below that field and show an appropriate error message")),Object(r.b)("tr",{parentName:"tbody"},Object(r.b)("td",{parentName:"tr",align:"center"},Object(r.b)("inlineCode",{parentName:"td"},"object")),Object(r.b)("td",{parentName:"tr",align:"center"},"rowData => { isValid: boolean; helperText: string }"),Object(r.b)("td",{parentName:"tr",align:null},"Return an object to optional block save and show a red bar below that field. A helper text will also be displayed, in red if isValid is false")))),Object(r.b)("div",{className:"admonition admonition-info alert alert--info"},Object(r.b)("div",{parentName:"div",className:"admonition-heading"},Object(r.b)("h5",{parentName:"div"},Object(r.b)("span",{parentName:"h5",className:"admonition-icon"},Object(r.b)("svg",{parentName:"span",xmlns:"http://www.w3.org/2000/svg",width:"14",height:"16",viewBox:"0 0 14 16"},Object(r.b)("path",{parentName:"svg",fillRule:"evenodd",d:"M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"}))),"info")),Object(r.b)("div",{parentName:"div",className:"admonition-content"},Object(r.b)("p",{parentName:"div"},'If a string is return from validate (even ""), it will be interpreted as an error and will block the submit'))),Object(r.b)("h3",{id:"examples"},"Examples"),Object(r.b)("pre",null,Object(r.b)("code",{parentName:"pre",className:"language-jsx",metastring:"live",live:!0},'function ValidationTable() {\n const data = [{ name: "Engel", surname: "Dominik", age: 27 }];\n const columns = [\n {\n title: "Name",\n field: "name",\n validate: (row) => (row.name || "").length !== 0,\n },\n {\n title: "Surname",\n field: "surname",\n validate: (row) =>\n (row.surname || "").length < 3\n ? "Surname must have at least 3 chars"\n : true,\n },\n {\n title: "Age",\n field: "age",\n type: "numeric",\n validate: (row) => ({\n isValid: row.age > 15,\n helperText: "Age must be above 15",\n }),\n },\n ];\n return (\n <MaterialTable\n data={data}\n columns={columns}\n editable={{\n onRowAdd: (newData) => {\n return new Promise((resolve, reject) => {\n // Must return a Promise\n });\n },\n onRowUpdate: (newData, oldData) => {\n return new Promise((resolve, reject) => {\n // Must return a Promise\n });\n },\n }}\n />\n );\n}\n')))}b.isMDXComponent=!0},165:function(e,t,n){"use strict";n.d(t,"a",(function(){return p})),n.d(t,"b",(function(){return O}));var a=n(0),r=n.n(a);function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function o(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?l(Object(n),!0).forEach((function(t){i(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):l(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function c(e,t){if(null==e)return{};var n,a,r=function(e,t){if(null==e)return{};var n,a,r={},i=Object.keys(e);for(a=0;a<i.length;a++)n=i[a],t.indexOf(n)>=0||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(a=0;a<i.length;a++)n=i[a],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}var b=r.a.createContext({}),d=function(e){var t=r.a.useContext(b),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},p=function(e){var t=d(e.components);return r.a.createElement(b.Provider,{value:t},e.children)},s="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return r.a.createElement(r.a.Fragment,{},t)}},m=r.a.forwardRef((function(e,t){var n=e.components,a=e.mdxType,i=e.originalType,l=e.parentName,b=c(e,["components","mdxType","originalType","parentName"]),p=d(n),s=a,m=p["".concat(l,".").concat(s)]||p[s]||u[s]||i;return n?r.a.createElement(m,o(o({ref:t},b),{},{components:n})):r.a.createElement(m,o({ref:t},b))}));function O(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var i=n.length,l=new Array(i);l[0]=m;var o={};for(var c in t)hasOwnProperty.call(t,c)&&(o[c]=t[c]);o.originalType=e,o[s]="string"==typeof e?e:a,l[1]=o;for(var b=2;b<i;b++)l[b]=n[b];return r.a.createElement.apply(null,l)}return r.a.createElement.apply(null,n)}m.displayName="MDXCreateElement"}}]);