-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcab00805.b762271c.js
More file actions
1 lines (1 loc) · 4.74 KB
/
cab00805.b762271c.js
File metadata and controls
1 lines (1 loc) · 4.74 KB
1
(window.webpackJsonp=window.webpackJsonp||[]).push([[27],{104:function(e,t,r){"use strict";r.d(t,"a",(function(){return p})),r.d(t,"b",(function(){return b}));var n=r(0),o=r.n(n);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function c(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?c(Object(r),!0).forEach((function(t){a(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):c(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function l(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},a=Object.keys(e);for(n=0;n<a.length;n++)r=a[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n<a.length;n++)r=a[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}var d=o.a.createContext({}),s=function(e){var t=o.a.useContext(d),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},p=function(e){var t=s(e.components);return o.a.createElement(d.Provider,{value:t},e.children)},m={inlineCode:"code",wrapper:function(e){var t=e.children;return o.a.createElement(o.a.Fragment,{},t)}},u=o.a.forwardRef((function(e,t){var r=e.components,n=e.mdxType,a=e.originalType,c=e.parentName,d=l(e,["components","mdxType","originalType","parentName"]),p=s(r),u=n,b=p["".concat(c,".").concat(u)]||p[u]||m[u]||a;return r?o.a.createElement(b,i(i({ref:t},d),{},{components:r})):o.a.createElement(b,i({ref:t},d))}));function b(e,t){var r=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var a=r.length,c=new Array(a);c[0]=u;var i={};for(var l in t)hasOwnProperty.call(t,l)&&(i[l]=t[l]);i.originalType=e,i.mdxType="string"==typeof e?e:n,c[1]=i;for(var d=2;d<a;d++)c[d]=r[d];return o.a.createElement.apply(null,c)}return o.a.createElement.apply(null,r)}u.displayName="MDXCreateElement"},95:function(e,t,r){"use strict";r.r(t),r.d(t,"frontMatter",(function(){return a})),r.d(t,"metadata",(function(){return c})),r.d(t,"toc",(function(){return i})),r.d(t,"default",(function(){return d}));var n=r(3),o=(r(0),r(104));const a={id:"createFormModel",title:"createFormModel",sidebar_label:"createFormModel",slug:"/api/create-form-model"},c={unversionedId:"createFormModel",id:"createFormModel",isDocsHomePage:!1,title:"createFormModel",description:"You can add a middleware to modify the behaviour of the inbuilt actions provided by Formst. For example, you can modify a form value by intercepting the setValue action.",source:"@site/docs/createFormModel.md",slug:"/api/create-form-model",permalink:"/docs/api/create-form-model",editUrl:"https://github.com/formstjs/formst-docs/docs/createFormModel.md",version:"current",sidebar_label:"createFormModel",sidebar:"someSidebar",previous:{title:"Middleware",permalink:"/docs/middleware"},next:{title:"Formst",permalink:"/docs/api/formst"}},i=[{value:"Usage",id:"usage",children:[]}],l={toc:i};function d({components:e,...t}){return Object(o.b)("wrapper",Object(n.a)({},l,t,{components:e,mdxType:"MDXLayout"}),Object(o.b)("p",null,"You can add a middleware to modify the behaviour of the inbuilt actions provided by ",Object(o.b)("strong",{parentName:"p"},"Formst"),". For example, you can modify a form value by intercepting the ",Object(o.b)("inlineCode",{parentName:"p"},"setValue")," action."),Object(o.b)("p",null,"Formst exports ",Object(o.b)("a",Object(n.a)({parentName:"p"},{href:"https://mobx-state-tree.js.org/concepts/middleware"}),"addMiddleware")," from MobX state tree. You can refer to ",Object(o.b)("a",Object(n.a)({parentName:"p"},{href:"https://mobx-state-tree.js.org/concepts/middleware"}),"their documentation")," for detailed usage and API details."),Object(o.b)("h3",{id:"usage"},"Usage"),Object(o.b)("pre",null,Object(o.b)("code",Object(n.a)({parentName:"pre"},{className:"language-tsx"}),"const TodoForm = createFormModel(\n 'TodoForm',\n {\n title: types.string,\n description: types.string,\n },\n ...\n);\n\naddMiddleware(TodoForm, (call, next, abort) => {\n if (call.name === 'setValue') {\n const fieldName = call.args[0];\n if (fieldName === 'title') {\n call.args[1] = call.args[1].toUpperCase();\n }\n }\n\n next(call);\n});\n")),Object(o.b)("p",null,"To get all the available actions for a form model, refer to the ",Object(o.b)("a",Object(n.a)({parentName:"p"},{href:"https://github.com/formstjs/formst/blob/master/src/createFormModel.ts"}),"source code"),"."))}d.isMDXComponent=!0}}]);