-
Notifications
You must be signed in to change notification settings - Fork 0
/
1127-a6446d38b497cfcd912a.js
1 lines (1 loc) · 527 KB
/
1127-a6446d38b497cfcd912a.js
1
(self.webpackChunkzent_docs=self.webpackChunkzent_docs||[]).push([[1127],{21127:(n,a,s)=>{"use strict";s.r(a),s.d(a,{default:()=>Sn});var t=s(73450),p=s(73118),o=s(27378),e=s(57318),c=s(9071),l=s(53137),u=s(28239),k=s(41837),i=s(55390),r=s(92892),m=s(93976),d=s(5185),g=s(65436),y=s(70453),h=s(49633),f=s(39612),b=s(47287),v=s(92497),F=s(39215),w=s(85636),x=s(96681),j=s(78518),C=s(69220),q=s(71457),V=s(69717),z=s(33938),S=s(61705),N=s(34954),I=s(75774),A=s(89239),M=s(40027),E=s(72118),P=s(57925),R=s(12729),O=s(73811),B=s(23476),D=s(79280),T=s(80964),U=s(70158),L=s(29951),_=s(12030),H=s(82285),Y=s(38836),G=s(82010),Z=s(59935),$=s(95388),X=s(55445),J=s(17323),W=s(24246);function K(n,a){var s=Object.keys(n);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(n);a&&(t=t.filter((function(a){return Object.getOwnPropertyDescriptor(n,a).enumerable}))),s.push.apply(s,t)}return s}function Q(n){for(var a=1;a<arguments.length;a++){var s=null!=arguments[a]?arguments[a]:{};a%2?K(Object(s),!0).forEach((function(a){(0,t.Z)(n,a,s[a])})):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(s)):K(Object(s)).forEach((function(a){Object.defineProperty(n,a,Object.getOwnPropertyDescriptor(s,a))}))}return n}var nn=function(){function n(){var n=h.l0.useForm(f.d.View),a=o.useState(!1),s=(0,p.Z)(a,2),t=s[0],e=s[1],c=o.useState(!1),l=(0,p.Z)(c,2),u=l[0],k=l[1],i=o.useCallback((()=>{k(!0),setTimeout((()=>{n.initialize({name:"zent",password:"zenttnez",email:"[email protected]"}),k(!1)}),1e3)}),[n]);return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(h.l0,{layout:"horizontal",form:n,disabled:t,children:[(0,W.jsx)(b.C,{name:"name",label:(0,W.jsxs)("span",{children:["用户名 ",(0,W.jsx)(v.X,{trigger:"hover",content:"用户名用于个人账号登录",centerArrow:!0,children:(0,W.jsx)(F.J,{type:"error-circle-o"})}),":"]}),validators:[w.Ei(5,"用户名至少 5 个字"),w.BS(25,"用户名最多 25 个字")],helpDesc:"用户名为5-25个字",required:"必填"}),(0,W.jsx)(b.C,{name:"password",props:{type:"password"},label:"密码:",helpDesc:(0,W.jsxs)("span",{children:["密码由英文字母、数字组成",(0,W.jsx)("a",{href:"https://youzan.com",target:"_blank",children:"查看更多"})]}),validateOccasion:h.l0.ValidateOccasion.Blur|h.l0.ValidateOccasion.Change,validators:[w.uj(/^[a-zA-Z0-9]+$/,"只允许英文字母和数字")],notice:"重要提示:填写后无法修改,请谨慎设置",required:"必填"}),(0,W.jsx)(b.C,{className:"demo-form-basic-email",label:"E-Mail:",name:"email",validators:[w.C1("必填"),w.Do("请输入正确的邮箱")]}),(0,W.jsx)(x.z,{htmlType:"reset",children:"重置"}),(0,W.jsx)(x.z,{onClick:n.model.clear.bind(n.model),children:"清空"}),(0,W.jsx)(x.z,{loading:u,onClick:i,children:"初始化表单数据"}),(0,W.jsx)(x.z,{onClick:()=>n.model.clearError(),children:"清空错误信息"})]}),(0,W.jsx)(x.z,{style:{marginTop:24},onClick:()=>e((n=>!n)),children:t?"解除禁用":"禁用表单"})]})}return(0,W.jsx)(n,{})},an=function(){function n(){var n=h.l0.useForm(f.d.View);return(0,W.jsxs)(h.l0,{layout:"horizontal",form:n,children:[(0,W.jsx)(b.C,{name:"name",label:"昵称:",required:"请选择类型",props:{spellCheck:!1}}),(0,W.jsx)(j.A,{name:"type",label:"类型:",required:!0,props:{options:[{key:1,text:"普通用户"},{key:2,text:"高级用户"}]}}),(0,W.jsxs)(C.x,{name:"sex",label:"性别:",required:!0,validators:[w.C1("请选择性别")],children:[(0,W.jsx)(q.Y,{value:"1",children:"男"}),(0,W.jsx)(q.Y,{value:"2",children:"女"})]}),(0,W.jsxs)(V.I,{name:"hobbies",label:"兴趣标签:",required:"请选择标签",validators:[w.Ei(1,"请选择标签")],children:[(0,W.jsx)(z.X,{value:"movie",children:"电影"}),(0,W.jsx)(z.X,{value:"book",children:"书籍"}),(0,W.jsx)(z.X,{value:"travel",children:"旅行"})]}),(0,W.jsx)(S.w,{name:"age",label:"年龄:",defaultValue:12,props:{showStepper:!0}}),(0,W.jsx)(N.h,{name:"color",label:"喜欢的颜色:",defaultValue:"#5197FF"}),(0,W.jsx)(I.y,{name:"workTime",label:"工作时间:",defaultValue:["9:00:00","18:00:00"]}),(0,W.jsx)(A.z,{name:"dateRange",label:"身份证有效期:",type:"split",dateFormat:"YYYY-MM-DD HH:mm:ss",validators:[function(n){if(!n[0]||!n[1])return{name:"required",message:"请填写有效期"}}]}),(0,W.jsx)(M.K,{name:"isPublic",label:"公开个人信息:",defaultValue:!1}),(0,W.jsx)(E.h,{name:"agree",label:"同意许可条例:",children:"是"}),(0,W.jsx)(P.c,{name:"singleFile",label:"单文件上传:",props:{tips:"文件大小不超过 2M",maxSize:2097152}}),(0,W.jsx)(R.U,{name:"upload",label:"文件上传:",props:{tips:"单个文件不超过 2M",maxAmount:9,maxSize:2097152}}),(0,W.jsx)(O.j,{name:"imageUpload",label:"图片文件上传:",props:{tips:"单个文件不超过 2M",maxAmount:9,maxSize:2097152}}),(0,W.jsx)(x.z,{type:"primary",onClick:()=>B.g.info((0,W.jsx)("code",{children:(0,W.jsx)("pre",{children:JSON.stringify(n.getValue(),null,2)})})),children:"Values"})]})}return(0,W.jsx)(n,{})},sn=function(){function n(){var n=h.l0.useForm(f.d.View),a=o.useCallback((n=>(n.getValue(),new Promise((n=>{setTimeout(n,1e3)})))),[]),s=o.useCallback((()=>{B.g.success("表单提交成功")}),[]),t=o.useCallback((n=>{B.g.error("校验似乎出了点问题...")}),[]);return(0,W.jsxs)(h.l0,{form:n,layout:"horizontal",onSubmit:a,onSubmitSuccess:s,onSubmitFail:t,children:[(0,W.jsx)(b.C,{name:"name",label:"姓名:",required:!0}),(0,W.jsx)(x.z,{htmlType:"submit",type:"primary",children:"提交"})]})}return(0,W.jsx)(n,{})},tn=function(){function n(n,a){return n!==a.getSectionValue("password").password?{name:"passwordEqual",message:"两次填写的密码不一致"}:null}function a(n){if(10!==n.length&&15!==n.length)return{name:"idLength",message:"证件号码是10位或者15位数字"}}function s(){var s=h.l0.useForm(f.d.View),t=(0,o.useCallback)((()=>{s.resetValue()}),[s]),p=o.useCallback((n=>{n.getValue()}),[]);return(0,W.jsxs)(h.l0,{form:s,layout:"horizontal",scrollToError:!0,onSubmit:p,children:[(0,W.jsx)(b.C,{name:"name",label:"昵称:",required:!0,helpDesc:"正则校验",validators:[w.C1("请填写昵称"),w.uj(/^[a-zA-Z]+$/,"昵称只能是字母")]}),(0,W.jsx)(b.C,{name:"password",label:"密码:",required:!0,helpDesc:"非空校验",validators:[w.C1("请填写密码")],props:{type:"password"}}),(0,W.jsx)(b.C,{name:"confirmPw",label:"确认密码:",required:!0,helpDesc:"自定义校验函数",validators:[n],props:{type:"password"}}),(0,W.jsx)(b.C,{name:"email",label:"邮件:",helpDesc:"邮件校验",validators:[w.Do("请填写正确的邮件")]}),(0,W.jsx)(b.C,{name:"remark",label:"备注:",helpDesc:"文本输入",props:{type:"textarea",showCount:!0,maxCharacterCount:10},validators:[w.BS(10,"备注不能超过10个字符")]}),(0,W.jsx)(S.w,{name:"id",label:"证件号码:",required:!0,helpDesc:"自定义校验函数",validators:[a]}),(0,W.jsxs)(V.I,{name:"hobbies",label:"兴趣标签:",required:!0,helpDesc:"长度校验",validators:[w.Ei(2,"请至少选择两个")],children:[(0,W.jsx)(z.X,{value:"movie",children:"电影"}),(0,W.jsx)(z.X,{value:"book",children:"书籍"}),(0,W.jsx)(z.X,{value:"travel",children:"旅行"})]}),(0,W.jsx)(P.c,{name:"singleFile",label:"单文件上传:",props:{tips:"文件大小不超过 2M",maxSize:2097152},validators:[w.C1("请上传文件")]}),(0,W.jsx)(R.U,{name:"upload",label:"文件上传:",props:{tips:"单个文件不超过 2M",maxAmount:9,maxSize:2097152},validators:[w.Ei(1,"请上传文件")]}),(0,W.jsx)(O.j,{name:"imageUpload",label:"图片文件上传:",props:{tips:"单个文件不超过 2M",maxAmount:9,maxSize:2097152},validators:[w.Ei(1,"请上传图片")]}),(0,W.jsxs)("div",{className:"zent-form-actions",children:[(0,W.jsx)(x.z,{type:"primary",htmlType:"submit",children:"获取表单值"}),(0,W.jsx)(x.z,{type:"primary",outline:!0,onClick:t,children:"重置表单值"})]})]})}return(0,W.jsx)(s,{})},pn=function(){var n=h.l0.ValidateOption,a=h.l0.createAsyncValidator((()=>new Promise((n=>{setTimeout((()=>{n({name:"async",message:"from async validator"})}),100)}))));function s(a){if("blur"===a)return n.IncludeAsync}function t(){var t=h.l0.useForm(f.d.View),p=(0,o.useCallback)((()=>{t.resetValue()}),[t]),e=(0,o.useCallback)((()=>{t.validate(n.Default|n.IncludeAsync|n.IncludeUntouched|n.IncludeChildrenRecursively).then((()=>{B.g.success("Validate finished: ".concat(t.isValid()))}))}),[t]);return(0,W.jsxs)(h.l0,{form:t,layout:"horizontal",scrollToError:!0,children:[(0,W.jsx)(b.C,{name:"name",label:"昵称:",required:!0,getValidateOption:s,validators:[w.C1("请填写昵称"),w.uj(/^[a-zA-Z]+$/,"昵称只能是字母"),a]}),(0,W.jsxs)("div",{className:"zent-form-actions",children:[(0,W.jsx)(x.z,{type:"primary",onClick:e,children:"校验表单"}),(0,W.jsx)(x.z,{type:"primary",outline:!0,onClick:p,children:"重置表单值"})]})]})}return(0,W.jsx)(t,{})},on=function(){function n(n){return"no-limit"!==n.option&&n.count<=0?{name:"error",message:"次数限制不能为0"}:null}function a(n){return n.target.value}function s(){var n=h.l0.useField("option","no-limit"),s=h.l0.useField("count",0),t=D.RI((0,o.useCallback)((()=>n.isTouched=!0),[n]),D.kH(a,D.sV(n,h.l0.ValidateOption.Default))),p=D.sV(s,h.l0.ValidateOption.Default);return(0,W.jsxs)(q.Y.Group,{className:"form-demo-12-radio-group",value:n.value,onChange:t,children:[(0,W.jsx)(q.Y,{value:"no-limit",children:"不限制"}),(0,W.jsxs)(q.Y,{value:"limit",children:["限制",(0,W.jsx)(T.Y,Q(Q({},D.Jk(s)),{},{disabled:"no-limit"===n.value,value:s.value,onChange:p,onBlur:(0,o.useCallback)((()=>{s.isTouched=!0,s.validate()}),[s])})),"次"]})]})}function t(){var a=h.l0.useForm(f.d.View),t=(0,o.useCallback)((()=>Promise.resolve()),[]);return(0,W.jsxs)(h.l0,{form:a,layout:"horizontal",onSubmit:t,children:[(0,W.jsx)(U.C,{name:"values",validators:[n],children:(0,W.jsx)(s,{})}),(0,W.jsx)("div",{children:(0,W.jsx)(x.z,{htmlType:"submit",style:{marginTop:16},children:"提交"})})]})}return(0,W.jsx)(t,{})},en=function(){function n({label:n,name:a,helpDesc:s,validators:t,validateOption:p=L.GP.Empty,defaultValue:e="",props:c}){var l=h.l0.useField(a,e,[w.C1("请输入邮箱"),w.Do("请输入正确的邮箱"),...t||[]]),u=(0,o.useCallback)((n=>{l.isTouched=!0,l.value=n.target.value}),[l]),k=(0,o.useCallback)((()=>{l.validate(p)}),[l,p]);return(0,W.jsxs)(_.N,{label:n,required:!0,children:[(0,W.jsx)(H.I,Q(Q({},c),{},{value:l.value,onChange:u,onBlur:k,width:240})),l.error&&(0,W.jsx)(Y.X,{children:l.error.message}),(0,W.jsx)("p",{style:{color:"#ababab",fontSize:12},children:s})]})}function a(){var a=h.l0.useForm(f.d.View);return(0,W.jsxs)(h.l0,{form:a,layout:"horizontal",children:[(0,W.jsx)(n,{name:"email",label:"邮箱:",helpDesc:"这个字段总会在blur事件触发校验",validateOption:L.GP.IncludeUntouched|L.GP.IncludeAsync}),(0,W.jsx)(n,{name:"email",label:"邮箱2:",helpDesc:"这个字段只会在触发onChange之后才在blur事件触发校验",validateOption:L.GP.IncludeAsync})]})}return(0,W.jsx)(a,{})},cn=function(){var n=h.l0.FieldValue;function a(){var a=h.l0.useForm(f.d.View);return(0,W.jsxs)(h.l0,{form:a,layout:"horizontal",scrollToError:!0,children:[(0,W.jsx)(M.K,{label:"启用短信通知:",name:"shouldNotify"}),(0,W.jsx)(n,{name:"shouldNotify",children:n=>(0,W.jsx)(b.C,{name:"contact",label:(n?"手机号":"联系方式")+":",required:!0,validators:[X.y((n=>n.getFormValue().shouldNotify?"请填写手机号":"请填写联系方式"))(w.C1("123")),J.g((n=>{var a;return null===(a=n.getFormValue())||void 0===a?void 0:a.shouldNotify}))(w.uj(/^\d{11}$/,"请填写11位手机号"))]})})]})}return(0,W.jsx)(a,{})},ln=function(){o.useState,o.useEffect,o.useCallback;var n=h.l0.useForm,a=h.l0.useFieldArray,s=h.l0.useFormValid;function t(){var a=n(f.d.View);return(0,W.jsxs)(h.l0,{form:a,layout:"horizontal",children:[(0,W.jsx)(e,{form:a}),(0,W.jsxs)(U.C,{name:"set",children:[(0,W.jsx)(b.C,{required:!0,withoutError:!0,name:"field1",label:"字段-1"}),(0,W.jsx)(h.l0.FieldValid,{name:"field1",children:n=>(0,W.jsx)(_.N,{label:" ",children:(0,W.jsxs)("div",{children:["Field-1 is ",n?"valid":"invalid"]})})}),(0,W.jsx)(b.C,{required:!0,name:"field2",label:"字段-2"})]}),(0,W.jsx)(p,{})]})}function p(){var n=a("array");return(0,W.jsxs)(W.Fragment,{children:[n.children.map(((a,s)=>(0,W.jsx)("div",{children:(0,W.jsx)(b.C,{required:!0,model:a,label:"项目",props:{addonAfter:(0,W.jsx)(F.J,{type:"close",style:{cursor:"pointer"},onClick:()=>n.splice(s,1)})}})},a.id))),(0,W.jsx)(x.z,{type:"primary",onClick:()=>n.push(""),children:"Add"})]})}function e({form:n}){var a=s(n);return(0,W.jsxs)(G.b,{type:a?"success":"error",style:{marginBottom:24},children:["Form is ",a?"valid":"invalid"]})}return(0,W.jsx)(t,{})},un=function(){function n({name:n}){var a,s=h.l0.useFieldArray(n,[w.BS(3,"最多添加 3 项兴趣")]),t=(0,o.useCallback)((()=>{s.push(""),s.validate(L.GP.IncludeUntouched)}),[]);return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(x.z,{onClick:t,className:"add-btn",children:"添加兴趣爱好"}),(0,W.jsx)("ul",{children:s.children.map(((n,a)=>(0,W.jsxs)("li",{className:"hobby",children:[(0,W.jsx)(b.C,{model:n,label:"兴趣爱好".concat(a+1,":"),validators:[w.C1("请填写兴趣爱好")],props:{width:120}}),(0,W.jsx)("span",{className:"del-btn",onClick:()=>{s.splice(a,1),s.validate()},children:"删除该爱好"})]},n.id)))}),(0,W.jsx)(Y.X,{style:{marginLeft:128},children:null===(a=s.error)||void 0===a?void 0:a.message})]})}function a({remove:a,index:s}){var t=(0,o.useCallback)((()=>{a(s)}),[s,a]);return(0,W.jsxs)("li",{className:"members",children:[(0,W.jsxs)("div",{className:"member-title",children:[(0,W.jsxs)("span",{children:["成员",s+1]}),(0,W.jsx)(v.X,{centerArrow:!0,trigger:"hover",content:"删除该成员",children:(0,W.jsx)(F.J,{className:"del-btn",type:"close-circle",onClick:t})})]}),(0,W.jsx)(b.C,{name:"name",label:"名字:",required:!0,validators:[w.C1("请填写成员名字")],normalizeBeforeSubmit:n=>n.toUpperCase()}),(0,W.jsxs)(C.x,{name:"sex",label:"性别:",defaultValue:"1",required:!0,validators:[w.C1("请选择性别")],children:[(0,W.jsx)(q.Y,{value:"1",children:"男"}),(0,W.jsx)(q.Y,{value:"2",children:"女"})]}),(0,W.jsx)(n,{name:"hobbies"})]})}function s({name:n}){var s=h.l0.useFieldArray(n),t=(0,o.useCallback)((()=>{s.push({})}),[s]),p=(0,o.useCallback)((()=>{s.push({},{})}),[s]),e=(0,o.useCallback)((n=>{s.splice(n,1)}),[s]);return(0,W.jsxs)(W.Fragment,{children:[s.children.length<3&&(0,W.jsx)(x.z,{onClick:t,className:"add-btn",children:"添加一个成员"}),s.children.length<2&&(0,W.jsx)(x.z,{onClick:p,className:"add-btn",children:"添加两个成员"}),(0,W.jsx)("ul",{children:s.children.map(((n,s)=>(0,W.jsx)(U.C,{model:n,children:(0,W.jsx)(a,{index:s,remove:e})},n.id)))})]})}function t(){var n=h.l0.useForm(f.d.View),a=(0,o.useCallback)((()=>{n.patchValue({number:42,members:[{name:"john",sex:"1",hobbies:["H1"]}]})}),[n]),t=(0,o.useCallback)((()=>{}),[n]),p=(0,o.useCallback)((()=>{}),[n]);return(0,W.jsxs)(h.l0,{className:"demo-form",layout:"horizontal",form:n,children:[(0,W.jsx)(S.w,{name:"number",label:"总人数:",required:!0,validators:[w.C1("请填写总人数")]}),(0,W.jsx)(s,{name:"members"}),(0,W.jsxs)("div",{style:{marginTop:16},children:[(0,W.jsx)(x.z,{type:"primary",htmlType:"submit",onClick:t,children:"获取表单值"}),(0,W.jsx)(x.z,{type:"primary",htmlType:"submit",onClick:p,children:"获取表单提交值"}),(0,W.jsx)(x.z,{onClick:a,children:"设置 FieldArray 值"})]})]})}return(0,W.jsx)(t,{})},kn=function(){var n=h.l0.form,a=h.l0.field,s=h.l0.array,t=h.l0.set;function p({model:n}){var a=h.l0.useFieldArray(n),s=(0,o.useCallback)((()=>{a.push("")}),[]);return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(x.z,{onClick:s,className:"add-btn",children:"添加兴趣爱好"}),(0,W.jsx)("ul",{children:a.children.map(((n,s)=>(0,W.jsxs)("li",{className:"hobby",children:[(0,W.jsx)(b.C,{model:n,label:"兴趣爱好".concat(s+1,":"),props:{width:120}}),(0,W.jsx)("span",{className:"del-btn",onClick:()=>a.splice(s,1),children:"删除该爱好"})]},n.id)))})]})}function e({remove:n,index:a,model:s}){var t=s.children,e=t.name,c=t.sex,l=t.hobbies,u=(0,o.useCallback)((()=>{n(a)}),[a,n]);return(0,W.jsx)(U.C,{model:s,children:(0,W.jsxs)("li",{className:"members",children:[(0,W.jsxs)("div",{className:"member-title",children:[(0,W.jsxs)("span",{children:["成员",a+1]}),(0,W.jsx)(v.X,{centerArrow:!0,trigger:"hover",content:"删除该成员",children:(0,W.jsx)(F.J,{className:"del-btn",type:"close-circle",onClick:u})})]}),(0,W.jsx)(b.C,{model:e,label:"名字:",required:!0}),(0,W.jsxs)(C.x,{model:c,label:"性别:",required:!0,children:[(0,W.jsx)(q.Y,{value:"1",children:"男"}),(0,W.jsx)(q.Y,{value:"2",children:"女"})]}),(0,W.jsx)(p,{model:l})]})})}function c({model:n}){var a=h.l0.useFieldArray(n),s=(0,o.useCallback)((()=>{a.push({})}),[a]),t=(0,o.useCallback)((()=>{a.push({},{})}),[a]),p=(0,o.useCallback)((n=>{a.splice(n,1)}),[a]);return(0,W.jsxs)(W.Fragment,{children:[a.children.length<3&&(0,W.jsx)(x.z,{onClick:s,className:"add-btn",children:"添加一个成员"}),a.children.length<2&&(0,W.jsx)(x.z,{onClick:t,className:"add-btn",children:"添加两个成员"}),(0,W.jsx)("ul",{children:a.children.map(((n,a)=>(0,W.jsx)(e,{model:n,index:a,remove:p},n.id)))})]})}var l=n({number:a("").validators(w.C1("请填写总人数")),members:s(t({name:a("").validators(w.C1("请填写成员名字")).normalizeBeforeSubmit((n=>n.toUpperCase())),sex:a("1").validators(w.C1("请选择性别")),hobbies:s(a("").validators(w.C1("请填写兴趣爱好"))).defaultValue([])}))});function u(){var n=h.l0.useForm(l),a=n.model.children,s=a.number,t=a.members,p=(0,o.useCallback)((()=>{n.patchValue({number:42,members:[{name:"john",sex:"1",hobbies:["H1"]}]})}),[n]),e=(0,o.useCallback)((()=>{}),[n]),u=(0,o.useCallback)((()=>{}),[n]);return(0,W.jsxs)(h.l0,{className:"demo-form",layout:"horizontal",form:n,children:[(0,W.jsx)(S.w,{model:s,label:"总人数:",required:!0}),(0,W.jsx)(c,{model:t}),(0,W.jsxs)("div",{style:{marginTop:16},children:[(0,W.jsx)(x.z,{type:"primary",htmlType:"submit",onClick:e,children:"获取表单值"}),(0,W.jsx)(x.z,{type:"primary",htmlType:"submit",onClick:u,children:"获取表单提交值"}),(0,W.jsx)(x.z,{onClick:p,children:"设置 FieldArray 值"})]})]})}return(0,W.jsx)(u,{})},rn=function(){var n=h.l0.form,a=h.l0.field,s=n({contactType:a(1).validators(w.C1("请选择联系方式")),phone:a("").validators(w.uj(/\d{11}/,"手机号必须是 11 位数字")),email:a("").validators(w.Do("邮箱不正确"))});function t(){var n=o.useState(!1),a=(0,p.Z)(n,2),t=a[0],e=a[1],c=o.useCallback((n=>{e(n.target.checked)}),[e]),l=h.l0.useForm(s),u=o.useRef(null),k=o.useCallback(((n,a)=>{var s=u.current,p=l.model.removeChild(n);if(null!==p&&(u.current=p),!l.model.get(a)){var o=t?s:s.builder.build();l.model.registerChild(a,o)}}),[l,t]),i=h.l0.useModelValue(l.model.get("contactType"));o.useEffect((()=>{1===i?k("email","phone"):k("phone","email")}),[k,i]);var r=o.useCallback((()=>{}),[l]),m=h.l0.useNamedChildModel(l.model,"phone"),d=h.l0.useNamedChildModel(l.model,"email");return(0,W.jsxs)(h.l0,{className:"demo-form",layout:"horizontal",form:l,children:[(0,W.jsxs)(C.x,{model:l.model.get("contactType"),label:"联系方式",required:!0,children:[(0,W.jsx)(q.Y,{value:1,children:"手机号码"}),(0,W.jsx)(q.Y,{value:2,children:"电子邮箱"})]}),1===i&&m&&(0,W.jsx)(S.w,{model:m,label:"手机号码",required:!0}),2===i&&d&&(0,W.jsx)(b.C,{model:d,label:"电子邮箱",required:!0}),(0,W.jsxs)("div",{style:{marginTop:16},children:[(0,W.jsx)(x.z,{type:"primary",htmlType:"submit",onClick:r,children:"打印表单值"}),(0,W.jsx)(z.X,{checked:t,onChange:c,style:{marginLeft:16},children:"切换联系方式时时保留 model 状态"})]})]})}return(0,W.jsx)(t,{})},mn=function(){function n(){var n=h.l0.useForm(f.d.View);return(0,W.jsxs)(h.l0,{layout:"horizontal",form:n,children:[(0,W.jsx)(b.C,{name:"field1",label:"field1",normalizeBeforeBlur:n=>n.trim(),normalize:n=>n.toUpperCase(),format:n=>n.toLowerCase()}),(0,W.jsx)("label",{children:"实际值:"}),(0,W.jsx)(h.l0.FieldValue,{name:"field1"})]})}return(0,W.jsx)(n,{})},dn=function(){var n=()=>{var n=h.l0.useFieldArrayChildModels("nickname");return n?(0,W.jsxs)("div",{className:"form-demo-11-preview-nickname",children:[(0,W.jsx)("label",{children:"昵称:"}),n.map(((n,a)=>(0,W.jsx)(h.l0.FieldValue,{model:n,children:n=>"".concat(n," ")},a)))]}):null},a=()=>(0,W.jsxs)("div",{className:"form-demo-11-preview",children:[(0,W.jsx)(h.l0.FieldValue,{name:"name",children:n=>(0,W.jsx)("h3",{children:n})}),(0,W.jsxs)(h.l0.FieldSetValue,{name:"contact",children:[(0,W.jsxs)("div",{className:"form-demo-11-preview-phone",children:[(0,W.jsx)("label",{children:"电话:"}),(0,W.jsx)(h.l0.FieldValue,{name:"phone"})]}),(0,W.jsx)("div",{className:"form-demo-11-preview-address",children:(0,W.jsx)(h.l0.FieldValue,{name:"address"})})]}),(0,W.jsx)(n,{})]}),s=({model:n,last:a,add:s,del:t})=>{var p=h.l0.useField(n),e=(0,o.useCallback)((n=>{p.value=n.target.value}),[p]);return(0,W.jsxs)("div",{className:"form-demo-11-nickname",children:[(0,W.jsx)(H.I,Q(Q({},D.Jk(p)),{},{onChange:e,value:p.value})),(0,W.jsx)(F.J,{type:"close-circle",style:{color:"#da2626"},onClick:t}),a&&(0,W.jsx)(F.J,{type:"plus-circle",style:{color:"#4cb35d"},onClick:s})]})},t=()=>{var n=h.l0.useFieldArray("nickname",[],[""]),a=()=>n.push("");return(0,W.jsx)(_.N,{label:"昵称",children:n.children.map(((t,p)=>(0,W.jsx)(s,{model:t,last:n.children.length===p+1,add:a,del:()=>(a=>n.splice(a,1))(p)},p)))})},p=()=>(0,W.jsxs)("div",{children:[(0,W.jsx)(b.C,{label:"姓名",name:"name"}),(0,W.jsxs)(U.C,{name:"contact",children:[(0,W.jsx)(b.C,{label:"电话",name:"phone"}),(0,W.jsx)(b.C,{label:"联系地址",name:"address"})]}),(0,W.jsx)(t,{})]});function e(){var n=h.l0.useForm(f.d.View);return(0,W.jsxs)(h.l0,{form:n,layout:"horizontal",className:"form-demo-11",children:[(0,W.jsx)(a,{}),(0,W.jsx)(p,{})]})}return(0,W.jsx)(e,{})},gn=function(){o.useState,o.useEffect,o.useCallback;var n=h.l0.useForm,a=h.l0.useFieldArray,s=h.l0.useFormValue;function t(){var a=n(f.d.View);return(0,W.jsxs)(h.l0,{form:a,layout:"horizontal",children:[(0,W.jsx)(b.C,{required:!0,name:"name",label:"姓名"}),(0,W.jsx)(b.C,{name:"address",label:"地址"}),(0,W.jsxs)(U.C,{name:"stature",children:[(0,W.jsx)(b.C,{name:"weight",label:"体重"}),(0,W.jsx)(b.C,{name:"height",label:"身高"})]}),(0,W.jsx)(p,{}),(0,W.jsx)(e,{form:a})]})}function p(){var n=a("hobbies",[],["看书"]);return n.destroyOnUnmount=!0,(0,W.jsxs)(_.N,{label:"爱好",children:[n.children.map(((a,s)=>(0,W.jsx)("div",{children:(0,W.jsx)(b.C,{withoutLabel:!0,model:a,props:{addonAfter:(0,W.jsx)(F.J,{type:"close",style:{cursor:"pointer"},onClick:()=>n.splice(s,1)})}})},a.id))),(0,W.jsx)(x.z,{type:"primary",onClick:()=>n.push(""),children:"增加爱好"})]})}function e({form:n}){var a=s(n);return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)("div",{children:"Form Value"}),(0,W.jsx)("pre",{children:JSON.stringify(a,null,2)})]})}return(0,W.jsx)(t,{})},yn=function(){o.useState;var n=o.useCallback,a=h.l0.form({list:h.l0.array(h.l0.set({v:h.l0.field(0)})).defaultValue([{v:1},{v:2},{v:3}])});function s(){var n=h.l0.useForm(a);return(0,W.jsx)(h.l0,{form:n,layout:"horizontal",children:(0,W.jsx)(t,{})})}function t(){var a=h.l0.useFieldArray("list"),s=function(n){var a=(0,u.kL)((function(){return new Set})),s=(0,u.kL)((function(){return new c.X("")})),t=(0,o.useCallback)((function(n){var t=(0,y.Z)("batched-task-"),p=a.current,o=function(){p.delete(t),s.current.next(t)};p.add(t),s.current.next(t);var e=n();(0,g.Z)(e)?e.then(o,o):o()}),[a,s]),p=(0,k.m)((function(n){return n.pipe((0,r.z)((function(n){return(0,l.a)(n).pipe((0,m.h)((function(n){n[0];var s=n[1];return!a.current.has(s)})),(0,d.U)((function(n){return n[0]})))})))}),[n,s.current]);return[(0,i.R)(p),t]}(a.value$),t=(0,p.Z)(s,2),e=(t[0],t[1]),f=n((()=>{setTimeout((()=>{e((()=>new Promise((n=>{a.children.forEach((n=>{var a=n.get("v");a.value=a.value+1})),n()}))))}),0)}),[a,e]),v=n((()=>{setTimeout((()=>{a.children.forEach((n=>{var a=n.get("v");a.value=a.value+1}))}),0)}),[a]);return(0,W.jsxs)(W.Fragment,{children:[a.children.map(((n,a)=>(0,W.jsx)("div",{children:(0,W.jsx)(b.C,{model:n.get("v")})},n.id))),(0,W.jsx)(x.z,{onClick:f,children:"批量更新"}),(0,W.jsx)(x.z,{onClick:v,children:"逐个更新"})]})}return(0,W.jsx)(s,{})},hn=function(){function n({form:n}){var a=h.l0.useFieldValue(n.model.get("name"));return(0,W.jsxs)("p",{children:["姓名:",a]})}function a(){var a=h.l0.useForm(f.d.View);return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(h.l0,{layout:"horizontal",form:a,children:(0,W.jsx)(Z.q3.Provider,{value:{labelStyle:{flexBasis:80,justifyContent:"flex-start"}},children:(0,W.jsx)(b.C,{name:"name",label:"姓名:"})})}),(0,W.jsx)(n,{form:a})]})}return(0,W.jsx)(a,{})},fn=function(){function n(){var n=h.l0.useForm(f.d.View);return(0,o.useEffect)((()=>{var a=n.model.get("field1"),s=n.model.get("field2"),t=a.value$.subscribe((n=>{s.value=n}));return()=>t.unsubscribe()}),[n]),(0,W.jsxs)(h.l0,{form:n,layout:"horizontal",children:[(0,W.jsx)(b.C,{name:"field1",label:"field1"}),(0,W.jsx)(b.C,{name:"field2",label:"field2"})]})}return(0,W.jsx)(n,{})},bn=function(){function n({name:n,model:s,defaultValue:t="",validators:p=[],label:e,required:c,withoutLabel:l,style:u,className:k}){var i;if(n&&s)throw new Error("Cannot use name and model together.");var r=h.l0.useField(n||s,t,[...p,w.uj(/^[\d]{17}[\dXY]$/,"请输入合法的身份证号")]),m=o.useCallback((n=>{r.isTouched=!0;var a=n.target.value.replace(/\s/g,"");a.length<=18&&r.patchValue(a)}),[r]);return(0,W.jsxs)(_.N,{style:u,className:k,label:e,required:c,withoutLabel:l,children:[(0,W.jsx)(H.I,{value:a(r.value),width:220,onChange:m,onBlur:o.useCallback((()=>r.validate()),[r])}),(0,W.jsx)(Y.X,{children:null===(i=r.error)||void 0===i?void 0:i.message})]})}function a(n){for(var a=[6,10,12,14,18],s=n.length,t="",p=0;p<s;)a.includes(p)&&(t+=" "),t+=n[p],p++;return t}function s(){var a=h.l0.useForm(f.d.View);return(0,W.jsx)(h.l0,{form:a,layout:"horizontal",children:(0,W.jsx)(n,{name:"id",label:"身份证号:",required:!0,validators:[w.C1("请输入身份证号")]})})}return(0,W.jsx)(s,{})},vn=function(){var n=$.P.SelectTrigger,a=[{code:"+86",zh:"zhongguo",eng:"china",text:"中国 +86",key:0},{code:"+853",zh:"aomen",eng:"Macau",text:"中国澳门 +853",key:1}],s=(n,a)=>!!(a&&n.text.trim().toLowerCase().indexOf(a.trim().toLowerCase())>-1);function t(n){return n}var p=()=>{var p=h.l0.useField("areacode",a[0]),e=h.l0.useField("mobile","",[w.uj(/^\d{1,10}$/,"请输入正确的手机号")]),c=D.RI((0,o.useCallback)((()=>{p.isTouched=!0}),[p]),D.kH(t,D.sV(p,h.l0.ValidateOption.Default))),l=D.sV(e,h.l0.ValidateOption.Default);return(0,W.jsxs)(_.N,{className:"form-demo-multiple-value",label:"联系方式:",invalid:!!p.error||!!e.error,children:[(0,W.jsx)($.P,{className:"areacode",options:a,filter:s,trigger:n,width:160,value:p.value,onChange:c}),(0,W.jsx)(T.Y,Q(Q({style:{marginLeft:16},className:"phone-num",placeholder:"请填写手机号",width:160,value:e.value},D.Jk(e)),{},{onChange:l,onBlur:(0,o.useCallback)((()=>{e.isTouched=!0,e.validate()}),[e])})),(0,W.jsx)(h.l0.CombineErrors,{models:[p,e]})]})},e=()=>{var n=h.l0.useForm(f.d.View),a=(0,o.useCallback)((()=>{n.getValue()}),[n]),s=(0,o.useCallback)((()=>{n.resetValue()}),[n]);return(0,W.jsxs)(h.l0,{form:n,layout:"horizontal",children:[(0,W.jsx)(U.C,{name:"contactPhone",children:(0,W.jsx)(p,{})}),(0,W.jsxs)("div",{className:"zent-form__form-actions",children:[(0,W.jsx)(x.z,{type:"primary",onClick:a,children:"获取表单值"})," ",(0,W.jsx)(x.z,{type:"primary",outline:!0,onClick:s,children:"重置表单值"})]})]})};return(0,W.jsx)(e,{})},Fn=function(){function n(){var n=h.l0.useForm(f.d.View);return(0,W.jsxs)(h.l0,{layout:"horizontal",form:n,children:[(0,W.jsx)(b.C,{name:"field1",label:"field1",required:"请填写内容",helpDesc:"这个字段不会展示它自己的错误",withoutError:!0}),(0,W.jsx)(b.C,{name:"field2",label:"field2",required:"请填写内容"}),(0,W.jsx)(h.l0.CombineErrors,{names:["field1","field2"]})]})}return(0,W.jsx)(n,{})},wn=function(){var n={minWidth:270};function a(){var a=h.l0.useForm(f.d.View),s=(0,o.useState)("vertical"),t=(0,p.Z)(s,2),e=t[0],c=t[1],l=(0,o.useCallback)((n=>c(n.target.value)),[]),u=(0,o.useState)("column"),k=(0,p.Z)(u,2),i=k[0],r=k[1],m=(0,o.useCallback)((n=>r(n.target.value)),[]);return(0,W.jsxs)("div",{className:"form-layout",children:[(0,W.jsxs)("div",{className:"form-layout-option",children:[(0,W.jsx)("span",{className:"form-layout-option-name",children:"Layout:"}),(0,W.jsxs)(q.Y.Group,{value:e,onChange:l,children:[(0,W.jsx)(q.Y,{value:"vertical",children:"vertical"}),(0,W.jsx)(q.Y,{value:"horizontal",children:"horizontal"})]})]}),(0,W.jsxs)("div",{className:"form-layout-option",children:[(0,W.jsx)("span",{className:"form-layout-option-name",children:"Direction:"}),(0,W.jsxs)(q.Y.Group,{value:i,onChange:m,children:[(0,W.jsx)(q.Y,{value:"column",children:"column"}),(0,W.jsx)(q.Y,{value:"row",children:"row"})]})]}),(0,W.jsx)("hr",{}),(0,W.jsx)(h.l0,{layout:e,direction:i,form:a,children:(0,W.jsxs)(Z.q3.Provider,{value:{controlStyle:n},children:[(0,W.jsx)(b.C,{name:"name",label:"用户名:",value:""}),(0,W.jsx)(b.C,{name:"name2",label:"用户名2:",value:""}),(0,W.jsx)(b.C,{name:"name3",label:"用户名3:",value:""})]})}),(0,W.jsx)("div",{className:"zent-form-demo__form-actions",children:(0,W.jsx)(x.z,{type:"primary",htmlType:"submit",children:"获取表单值"})})]})}return(0,W.jsx)(a,{})},xn=function(){function n(){var n=h.l0.useForm(f.d.View);return(0,W.jsx)(h.l0,{layout:"horizontal",form:n,children:(0,W.jsxs)(Z.q3.Provider,{value:{labelStyle:{flexBasis:80,justifyContent:"flex-start"}},children:[(0,W.jsx)(b.C,{name:"name",label:"姓名:"}),(0,W.jsx)(b.C,{name:"contact",label:"联系方式:"})]})})}return(0,W.jsx)(n,{})};function jn(n){return(0,W.jsx)(n.tag,Q(Q({},n.attributes),{},{dangerouslySetInnerHTML:{__html:n.html}}))}function Cn(n){return(0,W.jsx)(jn,{tag:"section",html:n.html,attributes:{className:"zandoc-react-markdown"}})}function qn(n){return(0,W.jsx)(jn,{tag:"style",html:n.style})}function Vn(n,a){for(;n;)return n.offsetTop&&"static"!==getComputedStyle(n).position&&(a+=n.offsetTop),Vn(n.parentNode,a);return a}class zn extends o.Component{constructor(...n){super(...n),(0,t.Z)(this,"state",{showCode:!1}),(0,t.Z)(this,"toggle",(()=>{this.setState({showCode:!this.state.showCode})}))}render(){var n=this.state.showCode,a=this.props,s=a.title,t=a.src,p=a.children;return(0,W.jsxs)("div",{className:"zandoc-react-demo",children:[(0,W.jsx)("div",{className:"zandoc-react-demo__preview",children:p}),(0,W.jsxs)("div",{className:"zandoc-react-demo__bottom",onClick:this.toggle,children:[(0,W.jsx)("div",{className:"zandoc-react-demo__title",children:(0,W.jsx)("p",{children:s||""})}),(0,W.jsx)("i",{className:"zenticon zenticon-caret-up zandoc-react-demo__toggle ".concat(n?"zandoc-react-demo__toggle-on":"zandoc-react-demo__toggle-off")})]}),n&&(0,W.jsx)("pre",{className:"zandoc-react-demo__code",children:(0,W.jsx)(jn,{tag:"code",html:t,attributes:{className:"language-jsx"}})})]})}}class Sn extends o.Component{componentDidMount(){var n=location.hash;if(n){var a=document.querySelector('a[href="'.concat(n,'"]'));a&&(0,e.l)(document.documentElement,0,Vn(a,-9))}}render(){return o.createElement("div",{className:"zandoc-react-container"},o.createElement(qn,{style:'.demo-form-basic-email {\n\tmargin-left: 5px;\n}\n\n.zent-form__controls .zent-switch-small {\n\tmargin-top: 5px;\n}\n\n.form-demo-12-radio-group {\n\t\tdisplay: flex;\n\t\tflex-direction: column;\n\t}\n\n.form-demo-12-radio-group .zent-radio-wrap {\n\t\t\tdisplay: flex;\n\t\t\theight: 30px;\n\t\t\talign-items: center;\n\t\t}\n\n.form-demo-12-radio-group .zent-radio-wrap span:nth-child(2) {\n\t\t\t\tdisplay: flex;\n\t\t\t\talign-items: center;\n\t\t\t}\n\n.form-demo-12-radio-group .zent-radio-wrap .zent-input-wrapper {\n\t\t\t\tmargin: 0 10px;\n\t\t\t}\n\n.add-btn {\n\tmargin-left: 130px;\n}\n\n.demo-form .members {\n\t\tborder: 1px dashed #ccc;\n\t\tmargin: 20px 0;\n\t\tpadding: 10px 0;\n\t\tposition: relative;\n\t}\n\n.demo-form .members .del-btn {\n\t\t\tcolor: #666;\n\t\t\tcursor: pointer;\n\t\t\tposition: absolute;\n\t\t\tright: -8px;\n\t\t\ttop: -8px;\n\t\t}\n\n.demo-form .member-title{\n\t\tmargin: 0 10px;\n\t}\n\n.demo-form .hobby {\n\t\tmargin-top: 20px;\n\t\tposition: relative;\n\t}\n\n.demo-form .hobby .del-btn {\n\t\t\tcolor: #155bd4;\n\t\t\tcursor: pointer;\n\t\t\tfont-size: 12px;\n\t\t\tposition: absolute;\n\t\t\ttop: 6px;\n\t\t\tleft: 300px;\n\t\t\twidth: 100px;\n\t\t}\n\n.demo-form .hobby-title {\n\t\tmargin: 10px 0 5px;\n\t}\n\n.demo-form .zenticon {\n\t\tmargin-left: 10px;\n\t}\n\n.form-demo-11 {\n\t\tdisplay: flex;\n\t}\n\n.form-demo-11-preview {\n\t\t\tpadding: 15px;\n \twidth: 230px;\n\t\t\tmargin: 20px;\n \theight: 90px;\n \tborder-radius: 5px;\n\t\t\tbackground-size: 100% 100%;\n \tbackground-image: url("https://img.yzcdn.cn/public_files/2019/03/11/704e415d887541d2bf9ce945483af305.png!middle.webp");\n\t\t\tdisplay: flex;\n\t\t\tflex-direction: column;\n\t\t}\n\n.form-demo-11-preview h3 {\n\t\t\t\tcolor: #ffd700;\n\t\t\t\tmin-height: 30px;\n\t\t\t\ttext-align: right;\n\t\t\t\tfont-size: 16px;\n\t\t\t}\n\n.form-demo-11-preview-address {\n\t\t\t\tcolor: #333;\n\t\t\t\tfont-size: 10px;\n\t\t\t\tmargin-top: auto;\n\t\t\t}\n\n.form-demo-11-preview-phone {\n\t\t\t\ttext-align: right;\n\t\t\t\tcolor: #c0c0c0;\n\t\t\t\tfont-size: 12px;\n\t\t\t}\n\n.form-demo-11-preview-nickname {\n\t\t\t\tcolor: #333;\n\t\t\t\tfont-size: 12px;\n\t\t\t\tmargin-bottom: 5px;\n\t\t\t}\n\n.form-demo-11-nickname {\n\t\t\tdisplay: flex;\n\t\t\talign-items: center\n\t\t}\n\n.form-demo-11-nickname:not(:first-child) {\n\tmargin-top: 16px;\n}\n\n.form-demo-11-nickname .zenticon {\n\t\t\t\tmargin-left: 5px;\n\t\t\t\tcursor: pointer;\n}\n\n.form-demo-12-radio-group {\n\t\tdisplay: flex;\n\t\tflex-direction: column;\n\t}\n\n.form-demo-12-radio-group .zent-radio-wrap {\n\t\t\tdisplay: flex;\n\t\t\theight: 30px;\n\t\t\talign-items: center;\n\t\t}\n\n.form-demo-12-radio-group .zent-radio-wrap span:nth-child(2) {\n\t\t\t\tdisplay: flex;\n\t\t\t\talign-items: center;\n\t\t\t}\n\n.form-demo-12-radio-group .zent-radio-wrap .zent-input-wrapper {\n\t\t\t\tmargin: 0 10px;\n\t\t\t}\n\n.form-demo-multiple-value .zent-form-control-content {\n\tdisplay: flex;\n}\n\n.form-layout {\n\twidth: 800px;\n}\n\n.form-layout-option {\n\tmargin-bottom: 16px;\n\tdisplay: flex;\n\talign-items: center;\n}\n\n.form-layout-option-name {\n\twidth: 100px;\n}\n\n.demo-form-basic-email {\n\tmargin-left: 5px;\n}'}),o.createElement(Cn,{html:'<h2 class="anchor-heading"><a href="#form-biao-dan-zu-jian">¶</a><a href="javascript:void(0)" id="form-biao-dan-zu-jian" class="anchor-point"></a>Form 表单组件</h2>\n<h3 class="anchor-heading"><a href="#jing-gao">¶</a><a href="javascript:void(0)" id="jing-gao" class="anchor-point"></a>⚠️ 警告</h3>\n<p>这是新版的 <code>Form</code> 组件,和 <code>7.0.0</code> 之前版本的 <code>Form</code> 组件不兼容,可以在<a href="https://zent-contrib.github.io/zent-compat">这里查看老版 <code>Form</code> 组件的文档</a>。</p>\n<p><code>Form</code> 和其他组件相比,本身功能和 API 都相对复杂,请先仔细阅读完本文档再使用。</p>\n<h3 class="anchor-heading"><a href="#api-wen-dang">¶</a><a href="javascript:void(0)" id="api-wen-dang" class="anchor-point"></a>API 文档</h3>\n<p><code>Form</code> 的 API 较多,文档里遗漏某些 API 的话请尝试搜索 tsdoc 生成的 <a href="../../apidoc">API 文档</a>,同时可以在 <a href="https://github.com/youzan/zent/issues/new">Github 上提个 issue</a>,帮助我们改进文档,issue 里请详细描述少了哪个 API 或者组件的信息。</p>\n<h3 class="anchor-heading"><a href="#form-de-fen-ceng-jie-gou">¶</a><a href="javascript:void(0)" id="form-de-fen-ceng-jie-gou" class="anchor-point"></a>Form 的分层结构</h3>\n<p>为了帮助更好的理解和使用 <code>Form</code>,先从设计的角度对 <code>Form</code> 做一个概述。<code>Form</code> 设计上可以大致分为 3 层:</p>\n<ul>\n<li>数据层:这一层在内部由一个叫 <code>formulr</code> 的内部包构成,它和 UI 无关</li>\n<li>React 绑定层:这一层也在 <code>formulr</code> 内,但只包含最基础的 Hooks(例如 <code>useField</code> 等),依旧和 UI 无关</li>\n<li>UI 层:这一层负责处理数据层和 <code>Zent</code> 组件库的适配,这一层只处理 UI 逻辑,不关心数据的具体处理逻辑</li>\n</ul>\n<h3 class="anchor-heading"><a href="#shu-ju-ceng">¶</a><a href="javascript:void(0)" id="shu-ju-ceng" class="anchor-point"></a>数据层</h3>\n<p>数据层主要由各种类型的 model, validator 以及 builder 构成。model 主要分为以下几种:</p>\n<ul>\n<li><code>IModel</code> 这是最底层 interface,所有 model 都实现它</li>\n<li><code>BasicModel</code> 这是一个 model 的基类,所有 model 都继承自它</li>\n<li><code>FieldModel</code> 单个表单域的 model</li>\n<li><code>FieldArrayModel</code> 一组相同表单域的 model</li>\n<li><code>FieldSetModel</code> 一组有相关性的表单域,通常这些表单域作为一个整体才有意义,比如手机号的国家代码+号码</li>\n<li><code>FormModel</code> 继承自 <code>FieldSetModel</code>,从数据层看就是 <code>FieldSetModel</code>,但是额外添加了一些表单顶层才需要的能力</li>\n<li><code>ModelRef</code> 类似 React 的 ref 概念,它的用处是在不知道具体的 model 类型时用作占位元素。只有 <code>View</code> 模式下才会出现。</li>\n</ul>\n<p>model 是数据和状态的容器,所以 model 上只有操作数据和状态的方法。不管 model 是什么类型,一个 model 上一定维护着值、校验状态、错误信息以及 touched 等一些基础状态,以及读取/操作这些信息的方法。下面是所有 model 上一些常见的方法和属性列表,额外的方法和属性可以通过 <a href="../../apidoc">API 文档</a>中搜索相应的 model 类型查看。</p>\n<ul>\n<li><code>value</code> 获取 model 当前的值</li>\n<li><code>getSubmitValue()</code> 获取用于表单提交的值,可以通过 <code>Field</code> 的 <code>normalize</code> 属性自定义格式化逻辑</li>\n<li><code>initialize(value: Value)</code> 初始化 model 值</li>\n<li><code>patchValue(value: Value)</code> 更新 model 值</li>\n<li><code>reset()</code> 重置 model 为初始值</li>\n<li><code>clear()</code> 重置 model 为默认值</li>\n<li><code>valid()</code> 返回 model 是否通过检验,该函数不会触发校验</li>\n<li><code>validate(options?: ValidateOption)</code> 触发 model 上的校验逻辑</li>\n<li><code>error</code> 获取 model 上的错误信息</li>\n<li><code>clearError()</code> 清楚 model 的错误信息</li>\n<li><code>dirty()</code> model 值是否被修改过</li>\n<li><code>pristine()</code> model 值是否从未被修改过</li>\n<li><code>touched()</code> model 对应的 Field 是否被用户操作过</li>\n</ul>\n<p><code>FieldArrayModel</code> 上还有一批类似数组操作元素的方法,行为和数组上的方法一致,接受值或者 model 对象作为参数。</p>\n<ul>\n<li><code>push</code></li>\n<li><code>pop</code></li>\n<li><code>shift</code></li>\n<li><code>unshift</code></li>\n<li><code>splice</code></li>\n<li><code>filter</code> 该方法直接操作当前的 <code>FieldArrayModel</code> 对象,而不是返回一个新的 <code>FieldArrayModel</code></li>\n<li><code>sort</code></li>\n<li><code>children</code> 获取所有子 model,是个只读数组</li>\n<li><code>get(index: number)</code> 返回指定下标处的子 model 对象</li>\n</ul>\n<p><code>FieldSetModel</code> 上的额外方法:</p>\n<ul>\n<li><code>children</code> 获取所有子 model,是个只读对象</li>\n<li><code>get(name: string)</code> 返回指定名字的子 model 对象</li>\n<li><code>registerChild(name, model): void</code> 注册一个子 model 对象</li>\n<li><code>removeChild(name)</code> 删除一个子 model</li>\n</ul>\n<p>⚠️ 注意:不要直接操作 <code>FieldArrayModel</code> 和 <code>FieldSetModel</code> 的 <code>children</code> 属性(本身就是只读属性),请使用 model 上提供的 mutation API 操作,否则会破坏 model 内部数据一致性,导致不可预期的问题。</p>\n<p>validator 和 builder 下文会详细说明。</p>\n<h3 class="anchor-heading"><a href="#form-de-yun-xing-mo-shi">¶</a><a href="javascript:void(0)" id="form-de-yun-xing-mo-shi" class="anchor-point"></a>Form 的运行模式</h3>\n<p><strong>这是使用 <code>Form</code> 时的一个非常重要的概念,请一定理解清楚。另外,我们推荐使用 <code>Model</code> 模式,而非 <code>View</code> 模式。</strong></p>\n<p>在 <code>ModelRef</code> 里提到了 <code>Form</code> 的 <code>View</code> 模式,这里详细说明以下 <code>Form</code> 的两种运行模式(<code>FormStrategy</code>),<code>View</code> 模式和 <code>Model</code> 模式。</p>\n<ul>\n<li><code>View</code> 模式是指表单的 model 是通过 UI 的结构,由 <code>Form</code> 自动推导生成的。简单来说,先有 UI,再有 model。上面提到的 <code>ModelRef</code> 即是在一些场景下 model 还未生成时用来做占位的,所以才说 <code>ModelRef</code> 仅出现在 <code>View</code> 模式下。</li>\n<li><code>Model</code> 模式则是由开发者创建好表单的 model 结构,然后作为 <code>Form</code> 的初始化参数传入的,所以是先有 model,再有 UI。</li>\n</ul>\n<p><code>FormStrategy</code> 指明了表单是由视图驱动(View 模式)的还是独立数据驱动(Model 模式),两种模式在使用 API 时也会有差异。</p>\n<ul>\n<li>当使用 <code>View</code> 模式时,表单项组件和 <code>hooks</code> 接受一个 <code>name</code> 参数而不是一个 model。</li>\n<li>当使用 <code>Model</code> 时,由于数据层是在表单外构建的,表单组件必须直接传入该字段对应的 <code>model</code>,而不是 <code>name</code>;但是使用 Form 的 Hooks 时,支持传入字段 <code>name</code> 或者 <code>model</code>,这种场景相当于是一个只读的订阅行为。</li>\n<li>除了上述区别之外,<strong>不同模式下表单组件以及 <code>hooks</code> 会有一些参数不同</strong>,具体请查阅 <a href="../../apidoc">API 文档</a>。</li>\n</ul>\n<h3 class="anchor-heading"><a href="#chang-yong-form-api">¶</a><a href="javascript:void(0)" id="chang-yong-form-api" class="anchor-point"></a>常用 <code>Form</code> API</h3>\n<p><code>form</code> 对象具备一些基础的能力:</p>\n<ul>\n<li><code>form.submit()</code> 显式触发表单提交事件,会自动触发表单校验。</li>\n<li><code>form.isSubmitting</code> 表单是否在提交中。</li>\n<li><code>form.isSubmitFailed</code> 表单上一次提交是否失败。</li>\n<li><code>form.isSubmitSucceeded</code> 表单上一次提交是否成功。</li>\n<li><code>form.validate(options?: ValidateOption)</code> 触发一次表单校验。</li>\n<li><code>form.isValid()</code> 表单是否通过校验,不会自动触发 <code>form.validate</code>。</li>\n<li><code>form.isValidating()</code> 表单是否正在校验过程中。</li>\n<li><code>form.model</code> 获取表单对应的 model 对象。</li>\n<li><code>form.getValue()</code> 获取表单当前的值。</li>\n<li><code>form.getSubmitValue()</code> 获取表单当前的值,用于需要在提交前通过 <code>normalizeBeforeSubmit</code> 格式化表单值的场景。</li>\n<li><code>form.patchValue()</code> 更新给定字段的值。</li>\n<li><code>form.initialize()</code> 初始化表单值,同时将这个值作为表单的 <code>initialValue</code> 。</li>\n<li><code>form.resetValue()</code> 将所有字段重置为 <code>initialValue</code> ,不会触发表单事件,如果 <code>initialValue</code> 不存在,则使用 <code>defaultValue</code> 。</li>\n<li><code>form.clear()</code> 将所有字段赋值为 <code>defaultValue</code> ,同时清空 <code>initialValue</code> 。</li>\n<li><code>form.reset()</code> 显式触发表单重置事件 。</li>\n</ul>\n<h4 class="anchor-heading"><a href="#form-zu-jian-de-props">¶</a><a href="javascript:void(0)" id="form-zu-jian-de-props" class="anchor-point"></a><code>Form</code> 组件的 Props</h4>\n<ul>\n<li><code>form</code> <code>useForm</code> 的返回值</li>\n<li><code>layout</code> 表单项内的布局模式,支持水平布局和垂直布局,默认垂直</li>\n<li><code>direction</code> 表单项间的排列方式,支持水品排列和垂直排列,默认垂直</li>\n<li><code>disabled</code> 禁用表单输入,开启后表单内所有元素不可编辑。注意:自定义组件需要自己实现禁用逻辑和展示</li>\n<li><code>disableEnterSubmit</code> 禁用表单内 <code>input</code> 元素的回车提交功能</li>\n<li><code>onReset</code> 表单重置回调函数,<code>form.reset</code> 或者原生的 DOM 触发的 <code>reset</code> 事件都会触发 <code>onReset</code></li>\n<li><code>onSubmit</code> 表单提交回调函数,<code>form.submit</code> 或者原生的 DOM 触发的 <code>submit</code> 事件都会触发 <code>onSubmit</code></li>\n<li><code>onSubmitFail</code> 表单提交失败时的回调函数</li>\n<li><code>onSubmitSuccess</code> 表单提交成功时的回调函数</li>\n<li><code>scrollToError</code> 表单校验报错时自动滚动到第一个错误的位置</li>\n<li>\n<p><code>willScrollToError</code> 触发滚动到第一个错误前的回调函数,如果返回一个 <code>Promise</code>,当 <code>Promise</code> <code>resolve</code> 时才会继续执行滚动,<code>reject</code> 将终止滚动操作。 可以返回 <code>IFormScrollToErrorOptions</code> 用来调整滚动的节点和位置</p>\n<ul>\n<li><code>scrollContainer</code> 自定义滚动的 DOM 节点,默认 <code>document.body</code></li>\n<li><code>offsetX</code> 自定义滚动的 x 轴偏移量</li>\n<li><code>offsetY</code> 自定义滚动的 y 轴偏移量</li>\n</ul>\n</li>\n<li>详细参数请<a href="../../apidoc/interfaces/IFormProps.html">参考这里</a></li>\n</ul>\n<h4 class="anchor-heading"><a href="#defaultvalue-vs-initialvalue">¶</a><a href="javascript:void(0)" id="defaultvalue-vs-initialvalue" class="anchor-point"></a><code>defaultValue</code> vs <code>initialValue</code></h4>\n<ul>\n<li><code>initialValue</code>:初始值,在逻辑上作为表单首次展示的值,可以被更新。</li>\n<li><code>defaultValue</code>:缺省值,在表单没有输入时使用的值,组件一旦渲染就不可再被更新。</li>\n</ul>\n<h3 class="anchor-heading"><a href="#hooks">¶</a><a href="javascript:void(0)" id="hooks" class="anchor-point"></a>Hooks</h3>\n<p><code>Form</code> 提供以下基础的 hooks,在内置的这些 <code>Form</code> 组件无法满足需要时,可以使用这些 hooks 来封装自定义的 <code>Form</code> 组件。</p>\n<ul>\n<li><code>Form.useForm</code> 获取 <code>Form</code> 对象,<a href="../../apidoc/classes/Form.html#useForm">查看 API 文档</a></li>\n<li><code>Form.useField</code> 获取 <code>Field</code>,<a href="../../apidoc/classes/Form.html#useField">查看 API 文档</a></li>\n<li><code>Form.useFieldArray</code> 获取 <code>FieldArray</code>,<a href="../../apidoc/classes/Form.html#useFieldArray">查看 API 文档</a></li>\n<li><code>Form.useFieldSet</code> 获取 <code>FieldSet</code>,<a href="../../apidoc/classes/Form.html#useFieldSet">查看 API 文档</a></li>\n</ul>\n<h4 class="anchor-heading"><a href="#ji-chu-shi-yong-fang-fa">¶</a><a href="javascript:void(0)" id="ji-chu-shi-yong-fang-fa" class="anchor-point"></a>基础使用方法</h4>\n<p>所有表单组件必须包裹在一个 <code>Form</code> 组件内部,每一个表单项对应一个 <code>Field</code>,我们已经内置了 Zent 组件对应的 <code>Field</code> 组件;也可以使用自己封装的自定义表单项组件。</p>\n<ul>\n<li><code>FormInputField</code></li>\n<li><code>FormSelectField</code></li>\n<li><code>FormRadioGroupField</code></li>\n<li><code>FormCheckboxField</code></li>\n<li><code>FormCheckboxGroupField</code></li>\n<li><code>FormNumberInputField</code></li>\n<li><code>FormSwitchField</code></li>\n<li><code>FormColorPickerField</code></li>\n<li><code>FormDatePickerField</code></li>\n<li><code>FormWeekPickerField</code></li>\n<li><code>FormMonthPickerField</code></li>\n<li><code>FormQuarterPickerField</code></li>\n<li><code>FormYearPickerField</code></li>\n<li><code>FormTimePickerField</code></li>\n<li><code>FormTimeRangePickerField</code></li>\n<li><code>FormDateRangePickerField</code></li>\n<li><code>FormCombinedTimeRangePickerField</code></li>\n<li><code>FormCombinedDateRangePickerField</code></li>\n<li><code>FormDateRangeQuickPickerField</code></li>\n</ul>\n<p><code>Field</code> 组件支持的完整参数列表可以<a href="../../apidoc/interfaces/IFormFieldPropsBase.html">参考这里</a>,以及<a href="../../apidoc/interfaces/IFormControlProps.html">这里除 <code>invalid</code> 之外的参数</a>;这些都是两种模式下通用的参数。</p>\n<ul>\n<li><code>after</code> 在表单项后面显示的自定义内容</li>\n<li><code>before</code> 在表单项前面显示的自定义内容</li>\n<li><code>format</code> 渲染前会先调用 <code>format</code> 格式化</li>\n<li><code>normalize</code> 触发 <code>onChange</code> 时会先经过 <code>normalize</code> 再写入到内部的 model 上</li>\n<li><code>getValidateOption</code> 根据触发校验的事件源头返回校验规则</li>\n<li><code>helpDesc</code> 表单项说明文案</li>\n<li><code>notice</code> 表单项警示性文案</li>\n<li><code>renderError</code> 自定义错误渲染,参数是 validator 返回的对象,一次只会有一个错误</li>\n<li><code>required</code> 是否必填,如果这项有值,会在校验规则里添加一个 <code>required</code> 规则,相当于一个快捷设置</li>\n<li><code>touchWhen</code> 什么时候标记表单项为 <code>touched</code></li>\n<li><code>validateOccasion</code> 什么时候触发校验</li>\n<li><code>withoutError</code> 不显示错误,开启后一般需要自行处理错误的展示</li>\n<li><code>withoutLabel</code> 默认不传 <code>label</code> 的时候也会留有 <code>label</code> 的空间,使用 <code>withoutLabel</code> 去掉这个留空</li>\n<li><code>label</code> 表单项的名称</li>\n<li><code>className</code> 自定义类名</li>\n<li><code>children</code> 不解释</li>\n<li><code>modelRef</code> Field 对应 model 的 ref,可以通过这个 <code>modelRef.current</code> 直接访问 model 上的方法和属性</li>\n</ul>\n<p><code>View</code> 模式还支持<a href="../../apidoc/interfaces/IFormFieldViewDrivenProps.html">以下参数</a>。</p>\n<ul>\n<li><code>defaultValue</code> 缺省值,作为没有用户输入时的值,不可变</li>\n<li><code>destroyOnUnmount</code> 是否在组件 <code>unmount</code> 的时候销毁 model 对象,销毁时机依赖 React 执行时机。<strong>使用前请看下面的注意事项。</strong></li>\n<li><code>initialValue</code> 初始值,在逻辑上作为字段首次展示的值,可变</li>\n<li><code>name</code> 表单项对应的数据字段名</li>\n<li><code>normalizeBeforeSubmit</code> 用于表单提交前格式化 <code>Field</code> 值的回调函数</li>\n<li><code>validators</code> 校验规则列表,执行的时候会按数组顺序逐个调用,直到所有都通过或者在第一个失败的地方停止</li>\n</ul>\n<p>注意:</p>\n<ul>\n<li>不要在 <code>View</code> 模式下通过<strong>条件渲染</strong>将同一个 <code>name</code> 的 \bmodel 渲染成不同的 <code>Field</code> 实例,并且同时在 <code>Field</code> 上开启 <code>destroyOnUnmount</code> 参数。我们认为这是很 tricky 的不合理用法,一旦发现这种场景,<code>name</code> 对应的那个 <code>Field</code> 将进入不可用状态,后续所有操作都会报错。</li>\n<li>在 <code>View</code> 模式下使用 <code>FieldArray</code> 时,由于该组件的特殊性,虽然此时传给 <code>Field</code> 的是个 <code>ModelRef</code>,按之前提到的规则这就是 <code>Model</code> 模式,但是校验规则还是需要设置在表单项上。</li>\n</ul>\n<p><code>Model</code> 模式还支持<a href="../../apidoc/interfaces/IFormFieldModelDrivenProps.html">以下参数</a>。注意,此模式下校验规则正常是设置在 model 上的,而不是表单项组件上。</p>\n<ul>\n<li><code>model</code> 表单项对应的数据</li>\n<li><code>initialValue</code> 初始值,用于覆盖 model 上的初始值,仅当值不等于 <code>undefined</code> 时生效</li>\n</ul>\n<p>注意:如果需要给 <code>Field</code> 封装的组件传递 props,需要将所有 props 通过 <code>props</code> 传递,例如 <code><FormInputField props={{ spellCheck: false }} /></code>,<code>spellCheck</code> 将会被透传到 <code>Input</code> 组件上;如果直接写在 <code>FormInputField</code> 上不会生效。</p>'}),o.createElement(zn,{title:"基础用法",id:"Demo1",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span>\n <span class="token maybe-class-name">FormInputField</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Form</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Validators</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Pop</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Icon</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">ButtonDirective</span><span class="token punctuation">,</span>\n<span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">Component</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> form <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useForm</span><span class="token punctuation">(</span><span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">View</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> <span class="token punctuation">[</span>disabled<span class="token punctuation">,</span> setDisabled<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token maybe-class-name">React</span><span class="token punctuation">.</span><span class="token method function property-access">useState</span><span class="token punctuation">(</span><span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> <span class="token punctuation">[</span>initializing<span class="token punctuation">,</span> setInitializing<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token maybe-class-name">React</span><span class="token punctuation">.</span><span class="token method function property-access">useState</span><span class="token punctuation">(</span><span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> initialize <span class="token operator">=</span> <span class="token maybe-class-name">React</span><span class="token punctuation">.</span><span class="token method function property-access">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token function">setInitializing</span><span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token function">setTimeout</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n form<span class="token punctuation">.</span><span class="token method function property-access">initialize</span><span class="token punctuation">(</span><span class="token punctuation">{</span>\n name<span class="token operator">:</span> <span class="token string">\'zent\'</span><span class="token punctuation">,</span>\n password<span class="token operator">:</span> <span class="token string">\'zenttnez\'</span><span class="token punctuation">,</span>\n email<span class="token operator">:</span> <span class="token string">\'[email protected]\'</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token function">setInitializing</span><span class="token punctuation">(</span><span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token number">1000</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>form<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form</span></span> <span class="token attr-name">layout</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>horizontal<span class="token punctuation">"</span></span> <span class="token attr-name">form</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>form<span class="token punctuation">}</span></span> <span class="token attr-name">disabled</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>disabled<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>name<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>span</span><span class="token punctuation">></span></span>\n 用户名<span class="token entity named-entity" title=" ">&nbsp;</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Pop</span></span> <span class="token attr-name">trigger</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>hover<span class="token punctuation">"</span></span> <span class="token attr-name">content</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>用户名用于个人账号登录<span class="token punctuation">"</span></span> <span class="token attr-name">centerArrow</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Icon</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>error-circle-o<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Pop</span></span><span class="token punctuation">></span></span><span class="token operator">:</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>span</span><span class="token punctuation">></span></span>\n <span class="token punctuation">}</span></span>\n <span class="token attr-name">validators</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">[</span>\n <span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">minLength</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">,</span> <span class="token string">\'用户名至少 5 个字\'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">maxLength</span><span class="token punctuation">(</span><span class="token number">25</span><span class="token punctuation">,</span> <span class="token string">\'用户名最多 25 个字\'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>\n <span class="token punctuation">]</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">helpDesc</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>用户名为5-25个字<span class="token punctuation">"</span></span>\n <span class="token attr-name">required</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>必填<span class="token punctuation">"</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>password<span class="token punctuation">"</span></span>\n <span class="token attr-name">props</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span> type<span class="token operator">:</span> <span class="token string">\'password\'</span> <span class="token punctuation">}</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>密码:<span class="token punctuation">"</span></span>\n <span class="token attr-name">helpDesc</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>span</span><span class="token punctuation">></span></span>\n 密码由英文字母、数字组成\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>a</span> <span class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>https://youzan.com<span class="token punctuation">"</span></span> <span class="token attr-name">target</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>_blank<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n 查看更多\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>a</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>span</span><span class="token punctuation">></span></span>\n <span class="token punctuation">}</span></span>\n <span class="token attr-name">validateOccasion</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>\n <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">ValidateOccasion</span></span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">Blur</span></span> <span class="token operator">|</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">ValidateOccasion</span></span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">Change</span></span>\n <span class="token punctuation">}</span></span>\n <span class="token attr-name">validators</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">[</span>\n <span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">pattern</span><span class="token punctuation">(</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex"><span class="token anchor function">^</span><span class="token charset"><span class="token charset-punctuation punctuation">[</span><span class="token range">a<span class="token range-punctuation operator">-</span>z</span><span class="token range">A<span class="token range-punctuation operator">-</span>Z</span><span class="token range">0<span class="token range-punctuation operator">-</span>9</span><span class="token charset-punctuation punctuation">]</span></span><span class="token quantifier number">+</span><span class="token anchor function">$</span></span><span class="token regex-delimiter">/</span></span><span class="token punctuation">,</span> <span class="token string">\'只允许英文字母和数字\'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>\n <span class="token punctuation">]</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">notice</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>重要提示:填写后无法修改,请谨慎设置<span class="token punctuation">"</span></span>\n <span class="token attr-name">required</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>必填<span class="token punctuation">"</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span>\n <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>demo-form-basic-email<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>E-Mail:<span class="token punctuation">"</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>email<span class="token punctuation">"</span></span>\n <span class="token attr-name">validators</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">[</span>\n <span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">required</span><span class="token punctuation">(</span><span class="token string">\'必填\'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">email</span><span class="token punctuation">(</span><span class="token string">\'请输入正确的邮箱\'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>\n <span class="token punctuation">]</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">htmlType</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>reset<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>重置<span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>form<span class="token punctuation">.</span><span class="token property-access">model</span><span class="token punctuation">.</span><span class="token method function property-access">clear</span><span class="token punctuation">.</span><span class="token method function property-access">bind</span><span class="token punctuation">(</span>form<span class="token punctuation">.</span><span class="token property-access">model</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n 清空\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">loading</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>initializing<span class="token punctuation">}</span></span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>initialize<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n 初始化表单数据\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> form<span class="token punctuation">.</span><span class="token property-access">model</span><span class="token punctuation">.</span><span class="token method function property-access">clearError</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span><span class="token punctuation">></span></span>清空错误信息<span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Form</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span>\n <span class="token attr-name">style</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span> marginTop<span class="token operator">:</span> <span class="token number">24</span> <span class="token punctuation">}</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token function">setDisabled</span><span class="token punctuation">(</span><span class="token parameter">prev</span> <span class="token arrow operator">=></span> <span class="token operator">!</span>prev<span class="token punctuation">)</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">></span></span>\n <span class="token punctuation">{</span>disabled <span class="token operator">?</span> <span class="token string">\'解除禁用\'</span> <span class="token operator">:</span> <span class="token string">\'禁用表单\'</span><span class="token punctuation">}</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token maybe-class-name">ReactDOM</span><span class="token punctuation">.</span><span class="token method function property-access">render</span><span class="token punctuation">(</span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Component</span></span> <span class="token punctuation">/></span></span><span class="token punctuation">,</span> mountNode<span class="token punctuation">)</span><span class="token punctuation">;</span>'},o.createElement(nn)),o.createElement(zn,{title:"使用内置表单元素组件",id:"Demo2",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span>\n <span class="token maybe-class-name">Form</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Field</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormInputField</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormSelectField</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormRadioGroupField</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormCheckboxField</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormCheckboxGroupField</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormColorPickerField</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormDateRangePickerField</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormNumberInputField</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormSwitchField</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Radio</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Checkbox</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Button</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormTimeRangePickerField</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormSingleUploadField</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormUploadField</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormImageUploadField</span><span class="token punctuation">,</span>\n<span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">Component</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> form <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useForm</span><span class="token punctuation">(</span><span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">View</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form</span></span> <span class="token attr-name">layout</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>horizontal<span class="token punctuation">"</span></span> <span class="token attr-name">form</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>form<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>name<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>昵称:<span class="token punctuation">"</span></span>\n <span class="token attr-name">required</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>请选择类型<span class="token punctuation">"</span></span>\n <span class="token attr-name">props</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span>\n spellCheck<span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormSelectField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>type<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>类型:<span class="token punctuation">"</span></span>\n <span class="token attr-name">required</span>\n <span class="token attr-name">props</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span>\n options<span class="token operator">:</span> <span class="token punctuation">[</span>\n <span class="token punctuation">{</span> key<span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span> text<span class="token operator">:</span> <span class="token string">\'普通用户\'</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token punctuation">{</span> key<span class="token operator">:</span> <span class="token number">2</span><span class="token punctuation">,</span> text<span class="token operator">:</span> <span class="token string">\'高级用户\'</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token punctuation">]</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormRadioGroupField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>sex<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>性别:<span class="token punctuation">"</span></span>\n <span class="token attr-name">required</span>\n <span class="token attr-name">validators</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">[</span><span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">required</span><span class="token punctuation">(</span><span class="token string">\'请选择性别\'</span><span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Radio</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>1<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>男<span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Radio</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Radio</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>2<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>女<span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Radio</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">FormRadioGroupField</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormCheckboxGroupField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>hobbies<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>兴趣标签:<span class="token punctuation">"</span></span>\n <span class="token attr-name">required</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>请选择标签<span class="token punctuation">"</span></span>\n <span class="token attr-name">validators</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">[</span><span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">minLength</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">\'请选择标签\'</span><span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Checkbox</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>movie<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>电影<span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Checkbox</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Checkbox</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>book<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>书籍<span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Checkbox</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Checkbox</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>travel<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>旅行<span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Checkbox</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">FormCheckboxGroupField</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormNumberInputField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>age<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>年龄:<span class="token punctuation">"</span></span>\n <span class="token attr-name">defaultValue</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">12</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">props</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span>\n showStepper<span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormColorPickerField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>color<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>喜欢的颜色:<span class="token punctuation">"</span></span>\n <span class="token attr-name">defaultValue</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>#5197FF<span class="token punctuation">"</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormTimeRangePickerField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>workTime<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>工作时间:<span class="token punctuation">"</span></span>\n <span class="token attr-name">defaultValue</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">[</span><span class="token string">\'9:00:00\'</span><span class="token punctuation">,</span> <span class="token string">\'18:00:00\'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">FormTimeRangePickerField</span></span><span class="token punctuation">></span></span>\n <span class="token operator"><</span><span class="token maybe-class-name">FormDateRangePickerField</span>\n name<span class="token operator">=</span><span class="token string">"dateRange"</span>\n label<span class="token operator">=</span><span class="token string">"身份证有效期:"</span>\n type<span class="token operator">=</span><span class="token string">"split"</span>\n dateFormat<span class="token operator">=</span><span class="token string">"YYYY-MM-DD HH:mm:ss"</span>\n validators<span class="token operator">=</span><span class="token punctuation">{</span><span class="token punctuation">[</span>\n <span class="token keyword">function</span> <span class="token function">required</span><span class="token punctuation">(</span><span class="token parameter">value</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>value<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span> <span class="token operator">||</span> <span class="token operator">!</span>value<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword control-flow">return</span> <span class="token punctuation">{</span>\n name<span class="token operator">:</span> <span class="token string">\'required\'</span><span class="token punctuation">,</span>\n message<span class="token operator">:</span> <span class="token string">\'请填写有效期\'</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token punctuation">]</span><span class="token punctuation">}</span>\n <span class="token operator">/</span><span class="token operator">></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormSwitchField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>isPublic<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>公开个人信息:<span class="token punctuation">"</span></span>\n <span class="token attr-name">defaultValue</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token boolean">false</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormCheckboxField</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>agree<span class="token punctuation">"</span></span> <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>同意许可条例:<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n 是\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">FormCheckboxField</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormSingleUploadField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>singleFile<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>单文件上传:<span class="token punctuation">"</span></span>\n <span class="token attr-name">props</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span>\n tips<span class="token operator">:</span> <span class="token string">\'文件大小不超过 2M\'</span><span class="token punctuation">,</span>\n maxSize<span class="token operator">:</span> <span class="token number">1024</span> <span class="token operator">*</span> <span class="token number">1024</span> <span class="token operator">*</span> <span class="token number">2</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormUploadField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>upload<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>文件上传:<span class="token punctuation">"</span></span>\n <span class="token attr-name">props</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span>\n tips<span class="token operator">:</span> <span class="token string">\'单个文件不超过 2M\'</span><span class="token punctuation">,</span>\n maxAmount<span class="token operator">:</span> <span class="token number">9</span><span class="token punctuation">,</span>\n maxSize<span class="token operator">:</span> <span class="token number">1024</span> <span class="token operator">*</span> <span class="token number">1024</span> <span class="token operator">*</span> <span class="token number">2</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormImageUploadField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>imageUpload<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>图片文件上传:<span class="token punctuation">"</span></span>\n <span class="token attr-name">props</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span>\n tips<span class="token operator">:</span> <span class="token string">\'单个文件不超过 2M\'</span><span class="token punctuation">,</span>\n maxAmount<span class="token operator">:</span> <span class="token number">9</span><span class="token punctuation">,</span>\n maxSize<span class="token operator">:</span> <span class="token number">1024</span> <span class="token operator">*</span> <span class="token number">1024</span> <span class="token operator">*</span> <span class="token number">2</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span>\n <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>primary<span class="token punctuation">"</span></span>\n <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span>\n <span class="token maybe-class-name">Notify</span><span class="token punctuation">.</span><span class="token method function property-access">info</span><span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>code</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>pre</span><span class="token punctuation">></span></span><span class="token punctuation">{</span><span class="token known-class-name class-name">JSON</span><span class="token punctuation">.</span><span class="token method function property-access">stringify</span><span class="token punctuation">(</span>form<span class="token punctuation">.</span><span class="token method function property-access">getValue</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token keyword null nil">null</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">}</span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>pre</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>code</span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span>\n <span class="token punctuation">}</span></span>\n <span class="token punctuation">></span></span>\n <span class="token maybe-class-name">Values</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Form</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token maybe-class-name">ReactDOM</span><span class="token punctuation">.</span><span class="token method function property-access">render</span><span class="token punctuation">(</span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Component</span></span> <span class="token punctuation">/></span></span><span class="token punctuation">,</span> mountNode<span class="token punctuation">)</span><span class="token punctuation">;</span>'},o.createElement(an)),o.createElement(zn,{title:"表单提交",id:"Demo15",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">,</span> <span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">,</span> <span class="token maybe-class-name">Notify</span><span class="token punctuation">,</span> <span class="token maybe-class-name">FormInputField</span> <span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">App</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> form <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useForm</span><span class="token punctuation">(</span><span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">View</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> onSubmit <span class="token operator">=</span> <span class="token maybe-class-name">React</span><span class="token punctuation">.</span><span class="token method function property-access">useCallback</span><span class="token punctuation">(</span><span class="token parameter">form</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token comment">// 在onSubmit触发之前,表单已校验通过</span>\n <span class="token keyword">const</span> value <span class="token operator">=</span> form<span class="token punctuation">.</span><span class="token method function property-access">getValue</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token comment">// onSubmit可以返回一个Promise,onSubmitSuccess会在其resolve之后调用</span>\n <span class="token keyword control-flow">return</span> <span class="token keyword">new</span> <span class="token class-name">Promise</span><span class="token punctuation">(</span><span class="token parameter">resolve</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token function">setTimeout</span><span class="token punctuation">(</span>resolve<span class="token punctuation">,</span> <span class="token number">1000</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> onSubmitSuccess <span class="token operator">=</span> <span class="token maybe-class-name">React</span><span class="token punctuation">.</span><span class="token method function property-access">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token maybe-class-name">Notify</span><span class="token punctuation">.</span><span class="token method function property-access">success</span><span class="token punctuation">(</span><span class="token string">\'表单提交成功\'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> onSubmitFail <span class="token operator">=</span> <span class="token maybe-class-name">React</span><span class="token punctuation">.</span><span class="token method function property-access">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">error</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span>error<span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token maybe-class-name">Notify</span><span class="token punctuation">.</span><span class="token method function property-access">error</span><span class="token punctuation">(</span><span class="token string">\'校验似乎出了点问题...\'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form</span></span>\n <span class="token attr-name">form</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>form<span class="token punctuation">}</span></span>\n <span class="token attr-name">layout</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>horizontal<span class="token punctuation">"</span></span>\n <span class="token attr-name">onSubmit</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>onSubmit<span class="token punctuation">}</span></span>\n <span class="token attr-name">onSubmitSuccess</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>onSubmitSuccess<span class="token punctuation">}</span></span>\n <span class="token attr-name">onSubmitFail</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>onSubmitFail<span class="token punctuation">}</span></span>\n <span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>name<span class="token punctuation">"</span></span> <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>姓名:<span class="token punctuation">"</span></span> <span class="token attr-name">required</span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">htmlType</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>submit<span class="token punctuation">"</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>primary<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n 提交\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Form</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token maybe-class-name">ReactDOM</span><span class="token punctuation">.</span><span class="token method function property-access">render</span><span class="token punctuation">(</span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">App</span></span> <span class="token punctuation">/></span></span><span class="token punctuation">,</span> mountNode<span class="token punctuation">)</span><span class="token punctuation">;</span>'},o.createElement(sn)),o.createElement(Cn,{html:'<h3 class="anchor-heading"><a href="#biao-dan-xiao-yan">¶</a><a href="javascript:void(0)" id="biao-dan-xiao-yan" class="anchor-point"></a>表单校验</h3>\n<p>通过 <code>Field</code> 上的 <code>validators</code> 参数来设置表单项的校验规则;也可以在 <code>FieldArray</code> 或者 <code>FieldSet</code> 上设置校验规则,这是高级用法,请<a href="#fei-field-ceng-ji-de-xiao-yan">参考这一节</a>。</p>\n<p>表单校验函数定义:</p>\n<pre><code class="language-ts"><span class="token keyword">type</span> <span class="token class-name">AsyncValidator<span class="token operator"><</span><span class="token constant">T</span><span class="token operator">></span></span> <span class="token operator">=</span> <span class="token punctuation">(</span>\n value<span class="token operator">:</span> <span class="token constant">T</span><span class="token punctuation">,</span>\n ctx<span class="token operator">:</span> ValidatorContext<span class="token operator"><</span><span class="token constant">T</span><span class="token operator">></span>\n<span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token builtin">Promise</span><span class="token operator"><</span>IMaybeError<span class="token operator"><</span><span class="token constant">T</span><span class="token operator">>></span> <span class="token operator">|</span> Observable<span class="token operator"><</span>IMaybeError<span class="token operator"><</span><span class="token constant">T</span><span class="token operator">>></span> <span class="token operator">|</span> <span class="token keyword">null</span><span class="token punctuation">;</span>\n\n<span class="token keyword">type</span> <span class="token class-name">SyncValidator<span class="token operator"><</span><span class="token constant">T</span><span class="token operator">></span></span> <span class="token operator">=</span> <span class="token punctuation">(</span>value<span class="token operator">:</span> <span class="token constant">T</span><span class="token punctuation">,</span> ctx<span class="token operator">:</span> ValidatorContext<span class="token operator"><</span><span class="token constant">T</span><span class="token operator">></span><span class="token punctuation">)</span> <span class="token operator">=></span> IMaybeError<span class="token operator"><</span><span class="token constant">T</span><span class="token operator">></span><span class="token punctuation">;</span></code></pre>\n<ul>\n<li>如果返回 <code>null</code> 或者 <code>undefined</code> 表示校验通过;当校验失败时返回一个<a href="../../apidoc/interfaces/IValidateResult.html">包含错误信息的对象</a>。</li>\n<li>支持返回 <code>Promise</code> 或 <code>Observable</code> 进行异步校验</li>\n<li>使用 <code>Form.createAsyncValidator</code> 来创建一个异步校验函数,<a href="../../apidoc/classes/Form.html#createAsyncValidator">查看函数定义</a>;通过 <code>Form.isAsyncValidator</code> 来判断函数是不是异步校验函数,<a href="../../apidoc/classes/Form.html#isAsyncValidator">查看函数定义</a></li>\n<li>通过 <code>Field</code> 的 <code>validateOccasion</code> 参数控制校验时机</li>\n<li>通过 <code>Field</code> 的 <code>getValidateOption</code> 参数控制校验规则的运行时机以及哪些校验规则需要运行</li>\n<li><code>validator</code> 的执行顺序是 <code>validators</code> 数组的元素顺序,通常建议把异步校验放在最后</li>\n<li>\n<p><code>ctx</code> 参数上有几个获取表单值的方法,当校验依赖其他字段的值时可能需要用到</p>\n<ul>\n<li><code>getFormValue()</code> 获取整个表单当前的值</li>\n<li><code>getSectionValue(...names)</code> 获取当前 FieldSet 或者 Form 下的某个字段的值</li>\n<li><code>getSection()</code> 或者所属 FieldSet 或者 Form 的 model 对象。</li>\n</ul>\n</li>\n</ul>\n<h4 class="anchor-heading"><a href="#nei-zhi-de-xiao-yan-gui-ze">¶</a><a href="javascript:void(0)" id="nei-zhi-de-xiao-yan-gui-ze" class="anchor-point"></a>内置的校验规则</h4>\n<ul>\n<li><a href="../../apidoc/modules/Validators.html#min"><code>Validators.min</code></a></li>\n<li><a href="../../apidoc/modules/Validators.html#max"><code>Validators.max</code></a></li>\n<li><a href="../../apidoc/modules/Validators.html#required"><code>Validators.required</code></a></li>\n<li><a href="../../apidoc/modules/Validators.html#requiredTrue"><code>Validators.requiredTrue</code></a></li>\n<li><a href="../../apidoc/modules/Validators.html#email"><code>Validators.email</code></a></li>\n<li><a href="../../apidoc/modules/Validators.html#minLength"><code>Validators.minLength</code></a></li>\n<li><a href="../../apidoc/modules/Validators.html#maxLength"><code>Validators.maxLength</code></a></li>\n<li><a href="../../apidoc/modules/Validators.html#pattern"><code>Validators.pattern</code></a></li>\n</ul>'}),o.createElement(zn,{title:"表单校验",id:"Demo4",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span>\n <span class="token maybe-class-name">Form</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Radio</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Checkbox</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Notify</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Validators</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormNumberInputField</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormInputField</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormSingleUploadField</span><span class="token punctuation">,</span>\n<span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n\n<span class="token comment">/**\n * 自定义表单校验,内置组件接受 renderError 参数,若不传默认会显示 message\n */</span>\n<span class="token keyword">function</span> <span class="token function">equalsPassword</span><span class="token punctuation">(</span><span class="token parameter">value<span class="token punctuation">,</span> ctx</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span>value <span class="token operator">!==</span> ctx<span class="token punctuation">.</span><span class="token method function property-access">getSectionValue</span><span class="token punctuation">(</span><span class="token string">\'password\'</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token property-access">password</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword control-flow">return</span> <span class="token punctuation">{</span>\n name<span class="token operator">:</span> <span class="token string">\'passwordEqual\'</span><span class="token punctuation">,</span>\n message<span class="token operator">:</span> <span class="token string">\'两次填写的密码不一致\'</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span>\n <span class="token keyword control-flow">return</span> <span class="token keyword null nil">null</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token keyword">function</span> <span class="token function">idLength</span><span class="token punctuation">(</span><span class="token parameter">value</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span>value<span class="token punctuation">.</span><span class="token property-access">length</span> <span class="token operator">!==</span> <span class="token number">10</span> <span class="token operator">&&</span> value<span class="token punctuation">.</span><span class="token property-access">length</span> <span class="token operator">!==</span> <span class="token number">15</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword control-flow">return</span> <span class="token punctuation">{</span>\n name<span class="token operator">:</span> <span class="token string">\'idLength\'</span><span class="token punctuation">,</span>\n message<span class="token operator">:</span> <span class="token string">\'证件号码是10位或者15位数字\'</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span>\n<span class="token punctuation">}</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">App</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> form <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useForm</span><span class="token punctuation">(</span><span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">View</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> resetForm <span class="token operator">=</span> <span class="token function">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n form<span class="token punctuation">.</span><span class="token method function property-access">resetValue</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>form<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> onSubmit <span class="token operator">=</span> <span class="token maybe-class-name">React</span><span class="token punctuation">.</span><span class="token method function property-access">useCallback</span><span class="token punctuation">(</span><span class="token parameter">form</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> value <span class="token operator">=</span> form<span class="token punctuation">.</span><span class="token method function property-access">getValue</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span>value<span class="token punctuation">)</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form</span></span>\n <span class="token attr-name">form</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>form<span class="token punctuation">}</span></span>\n <span class="token attr-name">layout</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>horizontal<span class="token punctuation">"</span></span>\n <span class="token attr-name">scrollToError</span>\n <span class="token attr-name">onSubmit</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>onSubmit<span class="token punctuation">}</span></span>\n <span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>name<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>昵称:<span class="token punctuation">"</span></span>\n <span class="token attr-name">required</span>\n <span class="token attr-name">helpDesc</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>正则校验<span class="token punctuation">"</span></span>\n <span class="token attr-name">validators</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">[</span>\n <span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">required</span><span class="token punctuation">(</span><span class="token string">\'请填写昵称\'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">pattern</span><span class="token punctuation">(</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex"><span class="token anchor function">^</span><span class="token charset"><span class="token charset-punctuation punctuation">[</span><span class="token range">a<span class="token range-punctuation operator">-</span>z</span><span class="token range">A<span class="token range-punctuation operator">-</span>Z</span><span class="token charset-punctuation punctuation">]</span></span><span class="token quantifier number">+</span><span class="token anchor function">$</span></span><span class="token regex-delimiter">/</span></span><span class="token punctuation">,</span> <span class="token string">\'昵称只能是字母\'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>\n <span class="token punctuation">]</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>password<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>密码:<span class="token punctuation">"</span></span>\n <span class="token attr-name">required</span>\n <span class="token attr-name">helpDesc</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>非空校验<span class="token punctuation">"</span></span>\n <span class="token attr-name">validators</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">[</span><span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">required</span><span class="token punctuation">(</span><span class="token string">\'请填写密码\'</span><span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">props</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span>\n type<span class="token operator">:</span> <span class="token string">\'password\'</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>confirmPw<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>确认密码:<span class="token punctuation">"</span></span>\n <span class="token attr-name">required</span>\n <span class="token attr-name">helpDesc</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>自定义校验函数<span class="token punctuation">"</span></span>\n <span class="token attr-name">validators</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">[</span>equalsPassword<span class="token punctuation">]</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">props</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span>\n type<span class="token operator">:</span> <span class="token string">\'password\'</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>email<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>邮件:<span class="token punctuation">"</span></span>\n <span class="token attr-name">helpDesc</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>邮件校验<span class="token punctuation">"</span></span>\n <span class="token attr-name">validators</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">[</span><span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">email</span><span class="token punctuation">(</span><span class="token string">\'请填写正确的邮件\'</span><span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>remark<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>备注:<span class="token punctuation">"</span></span>\n <span class="token attr-name">helpDesc</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>文本输入<span class="token punctuation">"</span></span>\n <span class="token attr-name">props</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span> type<span class="token operator">:</span> <span class="token string">\'textarea\'</span><span class="token punctuation">,</span> showCount<span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> maxCharacterCount<span class="token operator">:</span> <span class="token number">10</span> <span class="token punctuation">}</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">validators</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">[</span><span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">maxLength</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> <span class="token string">\'备注不能超过10个字符\'</span><span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormNumberInputField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>id<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>证件号码:<span class="token punctuation">"</span></span>\n <span class="token attr-name">required</span>\n <span class="token attr-name">helpDesc</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>自定义校验函数<span class="token punctuation">"</span></span>\n <span class="token attr-name">validators</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">[</span>idLength<span class="token punctuation">]</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormCheckboxGroupField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>hobbies<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>兴趣标签:<span class="token punctuation">"</span></span>\n <span class="token attr-name">required</span>\n <span class="token attr-name">helpDesc</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>长度校验<span class="token punctuation">"</span></span>\n <span class="token attr-name">validators</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">[</span><span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">minLength</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token string">\'请至少选择两个\'</span><span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Checkbox</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>movie<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>电影<span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Checkbox</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Checkbox</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>book<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>书籍<span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Checkbox</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Checkbox</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>travel<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>旅行<span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Checkbox</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">FormCheckboxGroupField</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormSingleUploadField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>singleFile<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>单文件上传:<span class="token punctuation">"</span></span>\n <span class="token attr-name">props</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span>\n tips<span class="token operator">:</span> <span class="token string">\'文件大小不超过 2M\'</span><span class="token punctuation">,</span>\n maxSize<span class="token operator">:</span> <span class="token number">1024</span> <span class="token operator">*</span> <span class="token number">1024</span> <span class="token operator">*</span> <span class="token number">2</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">validators</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">[</span><span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">required</span><span class="token punctuation">(</span><span class="token string">\'请上传文件\'</span><span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormUploadField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>upload<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>文件上传:<span class="token punctuation">"</span></span>\n <span class="token attr-name">props</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span>\n tips<span class="token operator">:</span> <span class="token string">\'单个文件不超过 2M\'</span><span class="token punctuation">,</span>\n maxAmount<span class="token operator">:</span> <span class="token number">9</span><span class="token punctuation">,</span>\n maxSize<span class="token operator">:</span> <span class="token number">1024</span> <span class="token operator">*</span> <span class="token number">1024</span> <span class="token operator">*</span> <span class="token number">2</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">validators</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">[</span><span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">minLength</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">\'请上传文件\'</span><span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormImageUploadField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>imageUpload<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>图片文件上传:<span class="token punctuation">"</span></span>\n <span class="token attr-name">props</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span>\n tips<span class="token operator">:</span> <span class="token string">\'单个文件不超过 2M\'</span><span class="token punctuation">,</span>\n maxAmount<span class="token operator">:</span> <span class="token number">9</span><span class="token punctuation">,</span>\n maxSize<span class="token operator">:</span> <span class="token number">1024</span> <span class="token operator">*</span> <span class="token number">1024</span> <span class="token operator">*</span> <span class="token number">2</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">validators</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">[</span><span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">minLength</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token string">\'请上传图片\'</span><span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>zent-form-actions<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>primary<span class="token punctuation">"</span></span> <span class="token attr-name">htmlType</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>submit<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n 获取表单值\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>primary<span class="token punctuation">"</span></span> <span class="token attr-name">outline</span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>resetForm<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n 重置表单值\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Form</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token maybe-class-name">ReactDOM</span><span class="token punctuation">.</span><span class="token method function property-access">render</span><span class="token punctuation">(</span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">App</span></span> <span class="token punctuation">/></span></span><span class="token punctuation">,</span> mountNode<span class="token punctuation">)</span><span class="token punctuation">;</span>'},o.createElement(tn)),o.createElement(zn,{title:"异步校验",id:"Demo5",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span>\n <span class="token maybe-class-name">Form</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Radio</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Checkbox</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Notify</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Validators</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormNumberInputField</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormInputField</span><span class="token punctuation">,</span>\n<span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n\n<span class="token keyword">const</span> <span class="token punctuation">{</span> <span class="token maybe-class-name">ValidateOption</span> <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">;</span>\n\n<span class="token keyword">const</span> asyncValidator <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">createAsyncValidator</span><span class="token punctuation">(</span>\n <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span>\n <span class="token keyword">new</span> <span class="token class-name">Promise</span><span class="token punctuation">(</span><span class="token parameter">resolve</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token function">setTimeout</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token function">resolve</span><span class="token punctuation">(</span><span class="token punctuation">{</span>\n name<span class="token operator">:</span> <span class="token string">\'async\'</span><span class="token punctuation">,</span>\n message<span class="token operator">:</span> <span class="token string">\'from async validator\'</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">)</span>\n<span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n<span class="token keyword">function</span> <span class="token function">getValidateOption</span><span class="token punctuation">(</span><span class="token parameter">source</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span>source <span class="token operator">===</span> <span class="token string">\'blur\'</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword control-flow">return</span> <span class="token maybe-class-name">ValidateOption</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">IncludeAsync</span></span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span>\n<span class="token punctuation">}</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">App</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> form <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useForm</span><span class="token punctuation">(</span><span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">View</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> resetForm <span class="token operator">=</span> <span class="token function">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n form<span class="token punctuation">.</span><span class="token method function property-access">resetValue</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>form<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> validateForm <span class="token operator">=</span> <span class="token function">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n form\n <span class="token comment">// 不传参数直接调用 validate() 等价于</span>\n <span class="token comment">// validate(ValidateOption.Default | ValidateOption.IncludeChildrenRecursively)</span>\n <span class="token punctuation">.</span><span class="token method function property-access">validate</span><span class="token punctuation">(</span>\n <span class="token maybe-class-name">ValidateOption</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">Default</span></span> <span class="token operator">|</span>\n <span class="token maybe-class-name">ValidateOption</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">IncludeAsync</span></span> <span class="token operator">|</span>\n <span class="token maybe-class-name">ValidateOption</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">IncludeUntouched</span></span> <span class="token operator">|</span>\n <span class="token maybe-class-name">ValidateOption</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">IncludeChildrenRecursively</span></span>\n <span class="token punctuation">)</span>\n <span class="token punctuation">.</span><span class="token method function property-access">then</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token maybe-class-name">Notify</span><span class="token punctuation">.</span><span class="token method function property-access">success</span><span class="token punctuation">(</span><span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">Validate finished: </span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>form<span class="token punctuation">.</span><span class="token method function property-access">isValid</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token interpolation-punctuation punctuation">}</span></span><span class="token template-punctuation string">`</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>form<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form</span></span> <span class="token attr-name">form</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>form<span class="token punctuation">}</span></span> <span class="token attr-name">layout</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>horizontal<span class="token punctuation">"</span></span> <span class="token attr-name">scrollToError</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>name<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>昵称:<span class="token punctuation">"</span></span>\n <span class="token attr-name">required</span>\n <span class="token attr-name">getValidateOption</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>getValidateOption<span class="token punctuation">}</span></span>\n <span class="token attr-name">validators</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">[</span>\n <span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">required</span><span class="token punctuation">(</span><span class="token string">\'请填写昵称\'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">pattern</span><span class="token punctuation">(</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex"><span class="token anchor function">^</span><span class="token charset"><span class="token charset-punctuation punctuation">[</span><span class="token range">a<span class="token range-punctuation operator">-</span>z</span><span class="token range">A<span class="token range-punctuation operator">-</span>Z</span><span class="token charset-punctuation punctuation">]</span></span><span class="token quantifier number">+</span><span class="token anchor function">$</span></span><span class="token regex-delimiter">/</span></span><span class="token punctuation">,</span> <span class="token string">\'昵称只能是字母\'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>\n asyncValidator<span class="token punctuation">,</span>\n <span class="token punctuation">]</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>zent-form-actions<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>primary<span class="token punctuation">"</span></span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>validateForm<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n 校验表单\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>primary<span class="token punctuation">"</span></span> <span class="token attr-name">outline</span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>resetForm<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n 重置表单值\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Form</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token maybe-class-name">ReactDOM</span><span class="token punctuation">.</span><span class="token method function property-access">render</span><span class="token punctuation">(</span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">App</span></span> <span class="token punctuation">/></span></span><span class="token punctuation">,</span> mountNode<span class="token punctuation">)</span><span class="token punctuation">;</span>'},o.createElement(pn)),o.createElement(Cn,{html:'<h3 class="anchor-heading"><a href="#fei-field-ceng-ji-de-xiao-yan">¶</a><a href="javascript:void(0)" id="fei-field-ceng-ji-de-xiao-yan" class="anchor-point"></a>非 <code>Field</code> 层级的校验</h3>\n<p><code>FieldSet</code> 和 <code>FieldArray</code> 和 <code>Field</code> 一样可以设置校验规则,这些校验规则是运行在 <code>FieldSet</code> 和 <code>FieldArray</code> 层级的,能拿到下层的所有数据,可以用来实现跨 <code>Field</code> 的校验。</p>'}),o.createElement(zn,{title:"字段交互",id:"Demo13",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> useCallback <span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">\'react\'</span><span class="token punctuation">;</span>\n<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span>\n <span class="token maybe-class-name">Form</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">NumberInput</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Radio</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Button</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FieldSet</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FieldUtils</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">ValidateOption</span><span class="token punctuation">,</span>\n<span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n\n<span class="token keyword">function</span> <span class="token function">sectionValidator</span><span class="token punctuation">(</span><span class="token parameter">values</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span>values<span class="token punctuation">.</span><span class="token property-access">option</span> <span class="token operator">!==</span> <span class="token string">\'no-limit\'</span> <span class="token operator">&&</span> values<span class="token punctuation">.</span><span class="token property-access">count</span> <span class="token operator"><=</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword control-flow">return</span> <span class="token punctuation">{</span>\n name<span class="token operator">:</span> <span class="token string">\'error\'</span><span class="token punctuation">,</span>\n message<span class="token operator">:</span> <span class="token string">\'次数限制不能为0\'</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span>\n <span class="token keyword control-flow">return</span> <span class="token keyword null nil">null</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token keyword">function</span> <span class="token function">getValue</span><span class="token punctuation">(</span><span class="token parameter">e</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword control-flow">return</span> e<span class="token punctuation">.</span><span class="token property-access">target</span><span class="token punctuation">.</span><span class="token property-access">value</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">Limit</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> option <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useField</span><span class="token punctuation">(</span><span class="token string">\'option\'</span><span class="token punctuation">,</span> <span class="token string">\'no-limit\'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> count <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useField</span><span class="token punctuation">(</span><span class="token string">\'count\'</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> onOptionChange <span class="token operator">=</span> <span class="token maybe-class-name">FieldUtils</span><span class="token punctuation">.</span><span class="token method function property-access">useMulti</span><span class="token punctuation">(</span>\n <span class="token function">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">(</span>option<span class="token punctuation">.</span><span class="token property-access">isTouched</span> <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>option<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FieldUtils</span><span class="token punctuation">.</span><span class="token method function property-access">usePipe</span><span class="token punctuation">(</span>\n getValue<span class="token punctuation">,</span>\n <span class="token maybe-class-name">FieldUtils</span><span class="token punctuation">.</span><span class="token method function property-access">useChangeHandler</span><span class="token punctuation">(</span>option<span class="token punctuation">,</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">ValidateOption</span></span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">Default</span></span><span class="token punctuation">)</span>\n <span class="token punctuation">)</span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> onLimitChange <span class="token operator">=</span> <span class="token maybe-class-name">FieldUtils</span><span class="token punctuation">.</span><span class="token method function property-access">useChangeHandler</span><span class="token punctuation">(</span>\n count<span class="token punctuation">,</span>\n <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">ValidateOption</span></span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">Default</span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Radio.Group</span></span>\n <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>form-demo-12-radio-group<span class="token punctuation">"</span></span>\n <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>option<span class="token punctuation">.</span><span class="token property-access">value</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">onChange</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>onOptionChange<span class="token punctuation">}</span></span>\n <span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Radio</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>no-limit<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>不限制<span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Radio</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Radio</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>limit<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n 限制\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">NumberInput</span></span>\n <span class="token spread"><span class="token punctuation">{</span><span class="token spread operator">...</span><span class="token maybe-class-name">FieldUtils</span><span class="token punctuation">.</span><span class="token method function property-access">useCompositionHandler</span><span class="token punctuation">(</span>count<span class="token punctuation">)</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">disabled</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>option<span class="token punctuation">.</span><span class="token property-access">value</span> <span class="token operator">===</span> <span class="token string">\'no-limit\'</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>count<span class="token punctuation">.</span><span class="token property-access">value</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">onChange</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>onLimitChange<span class="token punctuation">}</span></span>\n <span class="token attr-name">onBlur</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token function">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n count<span class="token punctuation">.</span><span class="token property-access">isTouched</span> <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">;</span>\n count<span class="token punctuation">.</span><span class="token method function property-access">validate</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>count<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n 次\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Radio</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Radio.Group</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">App</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> form <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useForm</span><span class="token punctuation">(</span><span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">View</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> onSubmit <span class="token operator">=</span> <span class="token function">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span><span class="token string">\'onSubmit\'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword control-flow">return</span> <span class="token known-class-name class-name">Promise</span><span class="token punctuation">.</span><span class="token method function property-access">resolve</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form</span></span> <span class="token attr-name">form</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>form<span class="token punctuation">}</span></span> <span class="token attr-name">layout</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>horizontal<span class="token punctuation">"</span></span> <span class="token attr-name">onSubmit</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>onSubmit<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FieldSet</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>values<span class="token punctuation">"</span></span> <span class="token attr-name">validators</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">[</span>sectionValidator<span class="token punctuation">]</span><span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Limit</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">FieldSet</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">htmlType</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>submit<span class="token punctuation">"</span></span> <span class="token attr-name">style</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span> marginTop<span class="token operator">:</span> <span class="token number">16</span> <span class="token punctuation">}</span><span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n 提交\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Form</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token maybe-class-name">ReactDOM</span><span class="token punctuation">.</span><span class="token method function property-access">render</span><span class="token punctuation">(</span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">App</span></span> <span class="token punctuation">/></span></span><span class="token punctuation">,</span> mountNode<span class="token punctuation">)</span><span class="token punctuation">;</span>'},o.createElement(on)),o.createElement(Cn,{html:'<h3 class="anchor-heading"><a href="#xiao-yan-xuan-xiang">¶</a><a href="javascript:void(0)" id="xiao-yan-xuan-xiang" class="anchor-point"></a>校验选项</h3>\n<p>校验选项共有以下几种:</p>\n<ul>\n<li><code>ValidateOption.Empty</code>:校验会往上层冒泡,但不往下递归触发校验,并且会包含没有修改过的 <code>Field</code>,不校验没有 touch 过的 <code>Field</code>,不触发异步校验</li>\n<li><code>ValidateOption.Default</code>:默认行为,等同于<code>ValidateOption.Empty</code></li>\n<li><code>ValidateOption.IncludeAsync</code>:校验时包含异步校验</li>\n<li><code>ValidateOption.IncludeUntouched</code>:仅对满足<code>!!model.touched() === true</code>的字段进行校验</li>\n<li><code>ValidateOption.IncludeChildrenRecursively</code>:递归校验下层的 <code>Field</code>,适用于直接从 <code>Form</code>,<code>FieldSet</code> 或者 <code>FieldArray</code> 触发的校验</li>\n<li><code>ValidateOption.ExcludePristine</code>:不校验没有修改过的 <code>Field</code></li>\n<li><code>ValidateOption.StopPropagation</code>:校验时不往上一级 <code>FieldSet</code> 或者 <code>FieldArray</code> 冒泡,冒泡会一直到最顶层的 <code>Form</code>。</li>\n</ul>\n<p>校验选项是一个 <code>BitSet</code>,在自定义表单组件中,使用 <code>Model</code> 上的 <code>validate</code> 方法进行校验时,使用 <code>|</code> 运算符联合所需的选项作为参数传入即可。</p>\n<p>不传参数调用 <code>form.validate()</code> 等价于 <code>form.validate(ValidateOption.Default)</code>。</p>'}),o.createElement(zn,{title:"校验选项",id:"Demo16",src:'<span class="token keyword module">import</span> <span class="token punctuation">{</span>\n <span class="token maybe-class-name">Form</span><span class="token punctuation">,</span>\n <span class="token known-class-name class-name">FormError</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Validators</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">ValidateOption</span><span class="token punctuation">,</span>\n<span class="token punctuation">}</span> <span class="token keyword module">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">RequiredEmail</span></span><span class="token punctuation">(</span><span class="token punctuation">{</span>\n label<span class="token punctuation">,</span>\n name<span class="token punctuation">,</span>\n helpDesc<span class="token punctuation">,</span>\n validators<span class="token punctuation">,</span>\n validateOption <span class="token operator">=</span> <span class="token maybe-class-name">ValidateOption</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">Empty</span></span><span class="token punctuation">,</span>\n defaultValue <span class="token operator">=</span> <span class="token string">\'\'</span><span class="token punctuation">,</span>\n props<span class="token punctuation">,</span>\n<span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> model <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useField</span><span class="token punctuation">(</span>name<span class="token punctuation">,</span> defaultValue<span class="token punctuation">,</span> <span class="token punctuation">[</span>\n <span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">required</span><span class="token punctuation">(</span><span class="token string">\'请输入邮箱\'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">email</span><span class="token punctuation">(</span><span class="token string">\'请输入正确的邮箱\'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>\n <span class="token spread operator">...</span><span class="token punctuation">(</span>validators <span class="token operator">||</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">,</span>\n <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword">const</span> onChange <span class="token operator">=</span> <span class="token function">useCallback</span><span class="token punctuation">(</span>\n <span class="token parameter">e</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n model<span class="token punctuation">.</span><span class="token property-access">isTouched</span> <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">;</span>\n model<span class="token punctuation">.</span><span class="token property-access">value</span> <span class="token operator">=</span> e<span class="token punctuation">.</span><span class="token property-access">target</span><span class="token punctuation">.</span><span class="token property-access">value</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token punctuation">[</span>model<span class="token punctuation">]</span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword">const</span> validate <span class="token operator">=</span> <span class="token function">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n model<span class="token punctuation">.</span><span class="token method function property-access">validate</span><span class="token punctuation">(</span>validateOption<span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>model<span class="token punctuation">,</span> validateOption<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormControl</span></span> <span class="token attr-name">label</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>label<span class="token punctuation">}</span></span> <span class="token attr-name">required</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Input</span></span>\n <span class="token spread"><span class="token punctuation">{</span><span class="token spread operator">...</span>props<span class="token punctuation">}</span></span>\n <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>model<span class="token punctuation">.</span><span class="token property-access">value</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">onChange</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>onChange<span class="token punctuation">}</span></span>\n <span class="token attr-name">onBlur</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>validate<span class="token punctuation">}</span></span>\n <span class="token attr-name">width</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">240</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token punctuation">{</span>model<span class="token punctuation">.</span><span class="token property-access">error</span> <span class="token operator">&&</span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormError</span></span><span class="token punctuation">></span></span><span class="token punctuation">{</span>model<span class="token punctuation">.</span><span class="token property-access">error</span><span class="token punctuation">.</span><span class="token property-access">message</span><span class="token punctuation">}</span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">FormError</span></span><span class="token punctuation">></span></span><span class="token punctuation">}</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>p</span> <span class="token attr-name">style</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span> color<span class="token operator">:</span> <span class="token string">\'#ababab\'</span><span class="token punctuation">,</span> fontSize<span class="token operator">:</span> <span class="token number">12</span> <span class="token punctuation">}</span><span class="token punctuation">}</span></span><span class="token punctuation">></span></span><span class="token punctuation">{</span>helpDesc<span class="token punctuation">}</span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>p</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">FormControl</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">App</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> form <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useForm</span><span class="token punctuation">(</span><span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">View</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form</span></span> <span class="token attr-name">form</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>form<span class="token punctuation">}</span></span> <span class="token attr-name">layout</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>horizontal<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">RequiredEmail</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>email<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>邮箱:<span class="token punctuation">"</span></span>\n <span class="token attr-name">helpDesc</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>这个字段总会在blur事件触发校验<span class="token punctuation">"</span></span>\n <span class="token attr-name">validateOption</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>\n <span class="token maybe-class-name">ValidateOption</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">IncludeUntouched</span></span> <span class="token operator">|</span> <span class="token maybe-class-name">ValidateOption</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">IncludeAsync</span></span>\n <span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">RequiredEmail</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>email<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>邮箱2:<span class="token punctuation">"</span></span>\n <span class="token attr-name">helpDesc</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>这个字段只会在触发onChange之后才在blur事件触发校验<span class="token punctuation">"</span></span>\n <span class="token attr-name">validateOption</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token maybe-class-name">ValidateOption</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">IncludeAsync</span></span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Form</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token maybe-class-name">ReactDOM</span><span class="token punctuation">.</span><span class="token method function property-access">render</span><span class="token punctuation">(</span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">App</span></span> <span class="token punctuation">/></span></span><span class="token punctuation">,</span> mountNode<span class="token punctuation">)</span><span class="token punctuation">;</span>'},o.createElement(en)),o.createElement(Cn,{html:'<h3 class="anchor-heading"><a href="#xiao-yan-zhong-jian-jian">¶</a><a href="javascript:void(0)" id="xiao-yan-zhong-jian-jian" class="anchor-point"></a>校验中间件</h3>\n<p>校验中间件作用于<strong>校验函数本身</strong>,可以把它视作用来装饰函数的装饰器;通过中间件可以为内置的校验函数提供一些额外能力,例如条件校验。</p>\n<p>使用 <code>FieldUtils.compose</code> 可以将多个中间件组合成一个,文档底部有 <code>FieldUtils.compose</code> 的 API 描述。</p>\n<p>校验中间件的函数签名:</p>\n<pre><code class="language-ts"><span class="token keyword">type</span> <span class="token class-name">Middleware<span class="token operator"><</span><span class="token constant">T</span><span class="token operator">></span></span> <span class="token operator">=</span> <span class="token punctuation">(</span>next<span class="token operator">:</span> IValidator<span class="token operator"><</span><span class="token constant">T</span><span class="token operator">></span><span class="token punctuation">)</span> <span class="token operator">=></span> IValidator<span class="token operator"><</span><span class="token constant">T</span><span class="token operator">></span><span class="token punctuation">;</span></code></pre>\n<h4 class="anchor-heading"><a href="#nei-zhi-de-xiao-yan-zhong-jian-jian">¶</a><a href="javascript:void(0)" id="nei-zhi-de-xiao-yan-zhong-jian-jian" class="anchor-point"></a>内置的校验中间件</h4>\n<ul>\n<li><code>when</code> 满足条件时才执行校验逻辑</li>\n<li><code>whenAsync</code> 同 <code>when</code>,适用于移步校验函数</li>\n<li><code>message</code> 根据值返回动态的错误信息</li>\n</ul>'}),o.createElement(zn,{title:"校验中间件",id:"Demo6",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span>\n <span class="token maybe-class-name">Form</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Validators</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">ValidatorMiddlewares</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormInputField</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormSwitchField</span><span class="token punctuation">,</span>\n<span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n\n<span class="token keyword">const</span> <span class="token punctuation">{</span> <span class="token maybe-class-name">FieldValue</span> <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">;</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">App</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> form <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useForm</span><span class="token punctuation">(</span><span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">View</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form</span></span> <span class="token attr-name">form</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>form<span class="token punctuation">}</span></span> <span class="token attr-name">layout</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>horizontal<span class="token punctuation">"</span></span> <span class="token attr-name">scrollToError</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormSwitchField</span></span> <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>启用短信通知:<span class="token punctuation">"</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>shouldNotify<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FieldValue</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>shouldNotify<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">{</span><span class="token parameter">shouldNotify</span> <span class="token arrow operator">=></span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>contact<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>\n <span class="token punctuation">(</span>shouldNotify <span class="token operator">?</span> <span class="token string">\'手机号\'</span> <span class="token operator">:</span> <span class="token string">\'联系方式\'</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token string">\':\'</span>\n <span class="token punctuation">}</span></span>\n <span class="token attr-name">required</span>\n <span class="token attr-name">validators</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">[</span>\n <span class="token maybe-class-name">ValidatorMiddlewares</span><span class="token punctuation">.</span><span class="token method function property-access">message</span><span class="token punctuation">(</span><span class="token parameter">ctx</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token keyword control-flow">return</span> ctx<span class="token punctuation">.</span><span class="token method function property-access">getFormValue</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token property-access">shouldNotify</span>\n <span class="token operator">?</span> <span class="token string">\'请填写手机号\'</span>\n <span class="token operator">:</span> <span class="token string">\'请填写联系方式\'</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">required</span><span class="token punctuation">(</span><span class="token string">\'123\'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">ValidatorMiddlewares</span><span class="token punctuation">.</span><span class="token method function property-access">when</span><span class="token punctuation">(</span>\n <span class="token parameter">ctx</span> <span class="token arrow operator">=></span> ctx<span class="token punctuation">.</span><span class="token method function property-access">getFormValue</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">?.</span>shouldNotify\n <span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">pattern</span><span class="token punctuation">(</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex"><span class="token anchor function">^</span><span class="token charclass class-name">\\d</span><span class="token quantifier number">{11}</span><span class="token anchor function">$</span></span><span class="token regex-delimiter">/</span></span><span class="token punctuation">,</span> <span class="token string">\'请填写11位手机号\'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>\n <span class="token punctuation">]</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">}</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">FieldValue</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Form</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token maybe-class-name">ReactDOM</span><span class="token punctuation">.</span><span class="token method function property-access">render</span><span class="token punctuation">(</span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">App</span></span> <span class="token punctuation">/></span></span><span class="token punctuation">,</span> mountNode<span class="token punctuation">)</span><span class="token punctuation">;</span>'},o.createElement(cn)),o.createElement(Cn,{html:'<h4 class="anchor-heading"><a href="#ding-yue-xiao-yan-zhuang-tai">¶</a><a href="javascript:void(0)" id="ding-yue-xiao-yan-zhuang-tai" class="anchor-point"></a>订阅校验状态</h4>\n<p>这个功能虽然不是很常用,但是 Zent 提供了 2 种监听表单校验状态的方法:</p>\n<ul>\n<li><code>Form.FieldValid</code>:接收 <code>name</code> 或 <code>model</code>,将其校验状态作为 <code>children</code> 的第一个参数</li>\n<li><code>Form.useFieldValid</code>:接收 <code>name</code> 或 <code>model</code>,返回其校验状态</li>\n<li><code>Form.useFormValid</code>:接收 <code>ZentForm</code> 对象(即 <code>useForm</code> 的返回值),返回表单的校验状态</li>\n<li>订阅 <code>FieldArray</code>, <code>FieldSet</code> 或者 <code>Form</code> 的校验状态可能会导致性能问题,因为这些是容器类型,订阅它们意味着需要订阅它们内部包含的所有表单项的校验状态变化,这是一个非常耗资源并且影响性能的操作,所以不推荐大范围频繁使用;开发模式下在 console 中会有一个警告信息。</li>\n<li>当遇到订阅导致重绘次数过多的性能问题时,可以考虑使用 <code>useObservableBatchedEagerState</code> 将操作做批处理,减少重绘次数。</li>\n</ul>'}),o.createElement(zn,{title:"响应式的校验状态",id:"Demo19",src:'<span class="token keyword module">import</span> <span class="token punctuation">{</span>\n <span class="token maybe-class-name">Form</span><span class="token punctuation">,</span>\n <span class="token known-class-name class-name">FormError</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormControl</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Input</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Validators</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormInputField</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FieldSet</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Button</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Notify</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Alert</span><span class="token punctuation">,</span>\n<span class="token punctuation">}</span> <span class="token keyword module">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n\n<span class="token keyword">const</span> <span class="token punctuation">{</span> useState<span class="token punctuation">,</span> useEffect<span class="token punctuation">,</span> useCallback <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token maybe-class-name">React</span><span class="token punctuation">;</span>\n<span class="token keyword">const</span> <span class="token punctuation">{</span> useForm<span class="token punctuation">,</span> useFieldArray<span class="token punctuation">,</span> useFormValid <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">;</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">App</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> form <span class="token operator">=</span> <span class="token function">useForm</span><span class="token punctuation">(</span><span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">View</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form</span></span> <span class="token attr-name">form</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>form<span class="token punctuation">}</span></span> <span class="token attr-name">layout</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>horizontal<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Preview</span></span> <span class="token attr-name">form</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>form<span class="token punctuation">}</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FieldSet</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>set<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span>\n <span class="token attr-name">required</span>\n <span class="token attr-name">withoutError</span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>field1<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>字段-1<span class="token punctuation">"</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form.FieldValid</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>field1<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">{</span><span class="token parameter">valid</span> <span class="token arrow operator">=></span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormControl</span></span> <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span> <span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span><span class="token punctuation">></span></span><span class="token maybe-class-name">Field</span><span class="token operator">-</span><span class="token number">1</span> is <span class="token punctuation">{</span>valid <span class="token operator">?</span> <span class="token string">\'valid\'</span> <span class="token operator">:</span> <span class="token string">\'invalid\'</span><span class="token punctuation">}</span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">FormControl</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">}</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Form.FieldValid</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span> <span class="token attr-name">required</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>field2<span class="token punctuation">"</span></span> <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>字段-2<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">FieldSet</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FieldArray</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Form</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">FieldArray</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> model <span class="token operator">=</span> <span class="token function">useFieldArray</span><span class="token punctuation">(</span><span class="token string">\'array\'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">{</span>model<span class="token punctuation">.</span><span class="token property-access">children</span><span class="token punctuation">.</span><span class="token method function property-access">map</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">child<span class="token punctuation">,</span> index</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">key</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>child<span class="token punctuation">.</span><span class="token property-access">id</span><span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n <span class="token operator"><</span><span class="token maybe-class-name">FormInputField</span>\n required\n model<span class="token operator">=</span><span class="token punctuation">{</span>child<span class="token punctuation">}</span>\n label<span class="token operator">=</span><span class="token string">"项目"</span>\n props<span class="token operator">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span>\n addonAfter<span class="token operator">:</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Icon</span></span>\n <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>close<span class="token punctuation">"</span></span>\n <span class="token attr-name">style</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span> cursor<span class="token operator">:</span> <span class="token string">\'pointer\'</span> <span class="token punctuation">}</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> model<span class="token punctuation">.</span><span class="token method function property-access">splice</span><span class="token punctuation">(</span>index<span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">}</span>\n <span class="token operator">/</span><span class="token operator">></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">}</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>primary<span class="token punctuation">"</span></span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> model<span class="token punctuation">.</span><span class="token method function property-access">push</span><span class="token punctuation">(</span><span class="token string">\'\'</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n <span class="token maybe-class-name">Add</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">Preview</span></span><span class="token punctuation">(</span><span class="token parameter"><span class="token punctuation">{</span> form <span class="token punctuation">}</span></span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token comment">// You will see a warning about performance issues in console.</span>\n <span class="token comment">// Only do this if you know what you are doing.</span>\n <span class="token keyword">const</span> valid <span class="token operator">=</span> <span class="token function">useFormValid</span><span class="token punctuation">(</span>form<span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Alert</span></span> <span class="token attr-name">type</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>valid <span class="token operator">?</span> <span class="token string">\'success\'</span> <span class="token operator">:</span> <span class="token string">\'error\'</span><span class="token punctuation">}</span></span> <span class="token attr-name">style</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span> marginBottom<span class="token operator">:</span> <span class="token number">24</span> <span class="token punctuation">}</span><span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n <span class="token maybe-class-name">Form</span> is <span class="token punctuation">{</span>valid <span class="token operator">?</span> <span class="token string">\'valid\'</span> <span class="token operator">:</span> <span class="token string">\'invalid\'</span><span class="token punctuation">}</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Alert</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token maybe-class-name">ReactDOM</span><span class="token punctuation">.</span><span class="token method function property-access">render</span><span class="token punctuation">(</span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">App</span></span> <span class="token punctuation">/></span></span><span class="token punctuation">,</span> mountNode<span class="token punctuation">)</span><span class="token punctuation">;</span>'},o.createElement(ln)),o.createElement(Cn,{html:'<h3 class="anchor-heading"><a href="#usefieldarray-he-fieldset">¶</a><a href="javascript:void(0)" id="usefieldarray-he-fieldset" class="anchor-point"></a><code>useFieldArray</code> 和 <code>FieldSet</code></h3>\n<ul>\n<li>\n<p><code>useFieldArray</code> 用于封装一组一样的表单项处理逻辑;<code>FieldSet</code> 用来封装一组相关的表单项处理逻辑。</p>\n</li>\n<li>\n<p>注意并没有所谓的 <code>FieldArray</code> 组件,直接使用 <code>Form.useFieldArray</code> 这个 hooks 即可。该函数有两个重载的实现,分别对应 <code>Form</code> 的两种运行模式。</p>\n</li>\n<li>\n<p><code>useFieldArray</code> 的参数定义请<a href="../../apidoc/classes/Form.html#useFieldArray">参考这里</a>。</p>\n</li>\n<li>\n<p><code>useFieldArray</code> 返回值是一个 <code>FieldArrayModel</code>,通过 <code>children</code> 就能访问到所有数据,一般在 <code>render</code> 函数里对 <code>children</code> 做 <code>map</code> 操作即可。</p>\n</li>\n<li>\n<p><code>FieldArrayModel</code> 上还有一些操作方法: <code>push</code>,<code>pop</code>,<code>shift</code>,<code>unshift</code>,<code>splice</code>,类似数组上对应的方法,用于操作子元素。对 <code>FieldArrayModel</code> 内元素做增删应该使用前面说的这些方法,不应该通过 <code>patchValue</code> 来实现增删,因为 <code>patchValue</code> 只更新值,会导致内部 model 状态不一致。</p>\n</li>\n<li>\n<p><code>FieldSet</code> 组件和 <code>Form</code> 一样有两种运行模式,<code>View</code> 模式可以通过 <code>name</code> 参数指定对应的数据来源;<code>Model</code> 模式则通过 <code>model</code> 参数或者 <code>name</code> 参数显式的设置数据来源。</p>\n</li>\n</ul>\n<p><code>FieldSet</code> 两种模式公用的参数可以在<a href="../../apidoc/interfaces/IFieldSetBaseProps.html">这里查看</a>。</p>\n<ul>\n<li><code>validators</code> 校验规则数组,按数组顺序执行,直到所有都通过或者在第一个失败的地方停止</li>\n<li><code>scrollAnchorRef</code> 表单提交时滚动到错误时的 DOM 元素的 ref(来自 <code>React.createRef</code> 或 <code>React.useRef</code>)</li>\n<li><code>renderError</code> 用于渲染整个 <code>FieldSet</code> 层面的错误</li>\n<li><code>children</code> 不解释</li>\n</ul>\n<p><code>View</code> 模式额外的参数:</p>\n<ul>\n<li><code>destroyOnUnmount</code> 是否在组件 <code>unmount</code> 的时候销毁 model 对象,销毁时机依赖 React 执行时机。</li>\n<li><code>normalizeBeforeSubmit</code> 用于表单提交前格式化 <code>FieldSet</code> 值的回调函数</li>\n<li><code>validators</code> <code>FieldSet</code> 本身的校验规则列表,注意和内部 Field 的校验规则没有关系。执行的时候会按数组顺序逐个调用,直到所有都通过或者在第一个失败的地方停止</li>\n</ul>'}),o.createElement(zn,{title:"FieldArray 基本使用",id:"Demo8",src:'<span class="token keyword module">import</span> <span class="token punctuation">{</span>\n <span class="token maybe-class-name">Form</span><span class="token punctuation">,</span>\n <span class="token known-class-name class-name">FormError</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Icon</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Pop</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Notify</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FieldModel</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FieldSetModel</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FieldSet</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Validators</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">ValidatorOption</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormNumberInputField</span><span class="token punctuation">,</span>\n<span class="token punctuation">}</span> <span class="token keyword module">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">Hobbies</span></span><span class="token punctuation">(</span><span class="token parameter"><span class="token punctuation">{</span> name <span class="token punctuation">}</span></span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> model <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useFieldArray</span><span class="token punctuation">(</span>name<span class="token punctuation">,</span> <span class="token punctuation">[</span>\n <span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">maxLength</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">,</span> <span class="token string">\'最多添加 3 项兴趣\'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>\n <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> addHobby <span class="token operator">=</span> <span class="token function">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n model<span class="token punctuation">.</span><span class="token method function property-access">push</span><span class="token punctuation">(</span><span class="token string">\'\'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n model<span class="token punctuation">.</span><span class="token method function property-access">validate</span><span class="token punctuation">(</span><span class="token maybe-class-name">ValidateOption</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">IncludeUntouched</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>addHobby<span class="token punctuation">}</span></span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>add-btn<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n 添加兴趣爱好\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>ul</span><span class="token punctuation">></span></span>\n <span class="token punctuation">{</span>model<span class="token punctuation">.</span><span class="token property-access">children</span><span class="token punctuation">.</span><span class="token method function property-access">map</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">child<span class="token punctuation">,</span> index</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>li</span> <span class="token attr-name">key</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>child<span class="token punctuation">.</span><span class="token property-access">id</span><span class="token punctuation">}</span></span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>hobby<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span>\n <span class="token attr-name">model</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>child<span class="token punctuation">}</span></span>\n <span class="token attr-name">label</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">兴趣爱好</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>index <span class="token operator">+</span> <span class="token number">1</span><span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">:</span><span class="token template-punctuation string">`</span></span><span class="token punctuation">}</span></span>\n <span class="token attr-name">validators</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">[</span><span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">required</span><span class="token punctuation">(</span><span class="token string">\'请填写兴趣爱好\'</span><span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">props</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span>\n width<span class="token operator">:</span> <span class="token number">120</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>span</span>\n <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>del-btn<span class="token punctuation">"</span></span>\n <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n model<span class="token punctuation">.</span><span class="token method function property-access">splice</span><span class="token punctuation">(</span>index<span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n model<span class="token punctuation">.</span><span class="token method function property-access">validate</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">></span></span>\n 删除该爱好\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>span</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>li</span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">}</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>ul</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormError</span></span> <span class="token attr-name">style</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span> marginLeft<span class="token operator">:</span> <span class="token number">128</span> <span class="token punctuation">}</span><span class="token punctuation">}</span></span><span class="token punctuation">></span></span><span class="token punctuation">{</span>model<span class="token punctuation">.</span><span class="token property-access">error</span><span class="token operator">?.</span>message<span class="token punctuation">}</span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">FormError</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">MemberInfo</span></span><span class="token punctuation">(</span><span class="token parameter"><span class="token punctuation">{</span> remove<span class="token punctuation">,</span> index <span class="token punctuation">}</span></span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> onRemoveClick <span class="token operator">=</span> <span class="token function">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token function">remove</span><span class="token punctuation">(</span>index<span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>index<span class="token punctuation">,</span> remove<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>li</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>members<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>member-title<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>span</span><span class="token punctuation">></span></span>\n 成员\n <span class="token punctuation">{</span>index <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">}</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>span</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Pop</span></span> <span class="token attr-name">centerArrow</span> <span class="token attr-name">trigger</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>hover<span class="token punctuation">"</span></span> <span class="token attr-name">content</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>删除该成员<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Icon</span></span>\n <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>del-btn<span class="token punctuation">"</span></span>\n <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>close-circle<span class="token punctuation">"</span></span>\n <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>onRemoveClick<span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Pop</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>name<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>名字:<span class="token punctuation">"</span></span>\n <span class="token attr-name">required</span>\n <span class="token attr-name">validators</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">[</span><span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">required</span><span class="token punctuation">(</span><span class="token string">\'请填写成员名字\'</span><span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">normalizeBeforeSubmit</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token parameter">name</span> <span class="token arrow operator">=></span> name<span class="token punctuation">.</span><span class="token method function property-access">toUpperCase</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormRadioGroupField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>sex<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>性别:<span class="token punctuation">"</span></span>\n <span class="token attr-name">defaultValue</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>1<span class="token punctuation">"</span></span>\n <span class="token attr-name">required</span>\n <span class="token attr-name">validators</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">[</span><span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">required</span><span class="token punctuation">(</span><span class="token string">\'请选择性别\'</span><span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Radio</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>1<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>男<span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Radio</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Radio</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>2<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>女<span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Radio</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">FormRadioGroupField</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Hobbies</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>hobbies<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>li</span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">Members</span></span><span class="token punctuation">(</span><span class="token parameter"><span class="token punctuation">{</span> name <span class="token punctuation">}</span></span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> model <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useFieldArray</span><span class="token punctuation">(</span>name<span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> addOne <span class="token operator">=</span> <span class="token function">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n model<span class="token punctuation">.</span><span class="token method function property-access">push</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>model<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> addTwo <span class="token operator">=</span> <span class="token function">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n model<span class="token punctuation">.</span><span class="token method function property-access">push</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>model<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> remove <span class="token operator">=</span> <span class="token function">useCallback</span><span class="token punctuation">(</span>\n <span class="token parameter">index</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n model<span class="token punctuation">.</span><span class="token method function property-access">splice</span><span class="token punctuation">(</span>index<span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token punctuation">[</span>model<span class="token punctuation">]</span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">{</span>model<span class="token punctuation">.</span><span class="token property-access">children</span><span class="token punctuation">.</span><span class="token property-access">length</span> <span class="token operator"><</span> <span class="token number">3</span> <span class="token operator">&&</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>addOne<span class="token punctuation">}</span></span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>add-btn<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n 添加一个成员\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">}</span>\n <span class="token punctuation">{</span>model<span class="token punctuation">.</span><span class="token property-access">children</span><span class="token punctuation">.</span><span class="token property-access">length</span> <span class="token operator"><</span> <span class="token number">2</span> <span class="token operator">&&</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>addTwo<span class="token punctuation">}</span></span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>add-btn<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n 添加两个成员\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">}</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>ul</span><span class="token punctuation">></span></span>\n <span class="token punctuation">{</span>model<span class="token punctuation">.</span><span class="token property-access">children</span><span class="token punctuation">.</span><span class="token method function property-access">map</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">child<span class="token punctuation">,</span> index</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FieldSet</span></span> <span class="token attr-name">key</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>child<span class="token punctuation">.</span><span class="token property-access">id</span><span class="token punctuation">}</span></span> <span class="token attr-name">model</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>child<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">MemberInfo</span></span> <span class="token attr-name">index</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>index<span class="token punctuation">}</span></span> <span class="token attr-name">remove</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>remove<span class="token punctuation">}</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">FieldSet</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">}</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>ul</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">App</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> form <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useForm</span><span class="token punctuation">(</span><span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">View</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> setArray <span class="token operator">=</span> <span class="token function">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n form<span class="token punctuation">.</span><span class="token method function property-access">patchValue</span><span class="token punctuation">(</span><span class="token punctuation">{</span>\n number<span class="token operator">:</span> <span class="token number">42</span><span class="token punctuation">,</span>\n members<span class="token operator">:</span> <span class="token punctuation">[</span>\n <span class="token punctuation">{</span>\n name<span class="token operator">:</span> <span class="token string">\'john\'</span><span class="token punctuation">,</span>\n sex<span class="token operator">:</span> <span class="token string">\'1\'</span><span class="token punctuation">,</span>\n hobbies<span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">\'H1\'</span><span class="token punctuation">]</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token punctuation">]</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>form<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword">const</span> getFormValue <span class="token operator">=</span> <span class="token function">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span>form<span class="token punctuation">.</span><span class="token method function property-access">getValue</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>form<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword">const</span> getSubmitValue <span class="token operator">=</span> <span class="token function">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span>form<span class="token punctuation">.</span><span class="token method function property-access">getSubmitValue</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>form<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form</span></span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>demo-form<span class="token punctuation">"</span></span> <span class="token attr-name">layout</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>horizontal<span class="token punctuation">"</span></span> <span class="token attr-name">form</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>form<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormNumberInputField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>number<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>总人数:<span class="token punctuation">"</span></span>\n <span class="token attr-name">required</span>\n <span class="token attr-name">validators</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">[</span><span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">required</span><span class="token punctuation">(</span><span class="token string">\'请填写总人数\'</span><span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Members</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>members<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">style</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span> marginTop<span class="token operator">:</span> <span class="token number">16</span> <span class="token punctuation">}</span><span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>primary<span class="token punctuation">"</span></span> <span class="token attr-name">htmlType</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>submit<span class="token punctuation">"</span></span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>getFormValue<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n 获取表单值\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>primary<span class="token punctuation">"</span></span> <span class="token attr-name">htmlType</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>submit<span class="token punctuation">"</span></span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>getSubmitValue<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n 获取表单提交值\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>setArray<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>设置 <span class="token maybe-class-name">FieldArray</span> 值<span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Form</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token maybe-class-name">ReactDOM</span><span class="token punctuation">.</span><span class="token method function property-access">render</span><span class="token punctuation">(</span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">App</span></span> <span class="token punctuation">/></span></span><span class="token punctuation">,</span> mountNode<span class="token punctuation">)</span><span class="token punctuation">;</span>'},o.createElement(un)),o.createElement(Cn,{html:'<h3 class="anchor-heading"><a href="#builder-api-he-model-mo-shi">¶</a><a href="javascript:void(0)" id="builder-api-he-model-mo-shi" class="anchor-point"></a>Builder API 和 Model 模式</h3>\n<p>使用 <code>Form</code> 的 <code>Model</code> 模式需要自己手动创建 model,我们提供了 builder API 来帮助完成这个操作。每个函数返回的都是一个 <code>Builder</code> 对象,<code>Builder</code> 对象都有一个 <code>validators</code> 方法用来配置 model 的校验规则。<strong>Builder API 都支持链式调用</strong>。</p>\n<ul>\n<li><code>Form.form</code> 参数是个对象,用来描述整个 <code>Form</code> model 的结构, <a href="../../apidoc/classes/Form.html#form">查看函数定义</a></li>\n<li><code>Form.field</code> 参数是 <code>Field</code> 的默认值,<a href="../../apidoc/classes/Form.html#field">查看函数定义</a></li>\n<li><code>Form.set</code> 参数是个对象,用来描述这个表单集合的结构,<a href="../../apidoc/classes/Form.html#set">查看函数定义</a></li>\n<li><code>Form.array</code> 参数是一个其他函数返回的 <code>Builder</code> 对象,<code>array</code> 返回的 <code>Builder</code> 对象上有 <code>defaultValue</code> 用于设置这个 array 中的表单项的默认值,<a href="../../apidoc/classes/Form.html#array">查看函数定义</a></li>\n</ul>'}),o.createElement(zn,{title:"从 Model 构建表单",id:"Demo9",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span>\n <span class="token maybe-class-name">Form</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Icon</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Pop</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Notify</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FieldModel</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FieldSetModel</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FieldSet</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Validators</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormNumberInputField</span><span class="token punctuation">,</span>\n<span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n\n<span class="token keyword">const</span> <span class="token punctuation">{</span> form<span class="token punctuation">,</span> field<span class="token punctuation">,</span> array<span class="token punctuation">,</span> set <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">;</span>\n\n<span class="token keyword">function</span> <span class="token function">hobbyFactory</span><span class="token punctuation">(</span>defaultValue <span class="token operator">=</span> <span class="token string">\'\'</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword control-flow">return</span> <span class="token function">field</span><span class="token punctuation">(</span>defaultValue<span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">Hobbies</span></span><span class="token punctuation">(</span><span class="token parameter"><span class="token punctuation">{</span> model<span class="token operator">:</span> propsModel <span class="token punctuation">}</span></span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> model <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useFieldArray</span><span class="token punctuation">(</span>propsModel<span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> addHobby <span class="token operator">=</span> <span class="token function">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n model<span class="token punctuation">.</span><span class="token method function property-access">push</span><span class="token punctuation">(</span><span class="token string">\'\'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>addHobby<span class="token punctuation">}</span></span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>add-btn<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n 添加兴趣爱好\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>ul</span><span class="token punctuation">></span></span>\n <span class="token punctuation">{</span>model<span class="token punctuation">.</span><span class="token property-access">children</span><span class="token punctuation">.</span><span class="token method function property-access">map</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">child<span class="token punctuation">,</span> index</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>li</span> <span class="token attr-name">key</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>child<span class="token punctuation">.</span><span class="token property-access">id</span><span class="token punctuation">}</span></span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>hobby<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span>\n <span class="token attr-name">model</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>child<span class="token punctuation">}</span></span>\n <span class="token attr-name">label</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">兴趣爱好</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>index <span class="token operator">+</span> <span class="token number">1</span><span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">:</span><span class="token template-punctuation string">`</span></span><span class="token punctuation">}</span></span>\n <span class="token attr-name">props</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span>\n width<span class="token operator">:</span> <span class="token number">120</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>span</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>del-btn<span class="token punctuation">"</span></span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> model<span class="token punctuation">.</span><span class="token method function property-access">splice</span><span class="token punctuation">(</span>index<span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n 删除该爱好\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>span</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>li</span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">}</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>ul</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">MemberInfo</span></span><span class="token punctuation">(</span><span class="token parameter"><span class="token punctuation">{</span> remove<span class="token punctuation">,</span> index<span class="token punctuation">,</span> model <span class="token punctuation">}</span></span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> <span class="token punctuation">{</span> name<span class="token punctuation">,</span> sex<span class="token punctuation">,</span> hobbies <span class="token punctuation">}</span> <span class="token operator">=</span> model<span class="token punctuation">.</span><span class="token property-access">children</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> onRemoveClick <span class="token operator">=</span> <span class="token function">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token function">remove</span><span class="token punctuation">(</span>index<span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>index<span class="token punctuation">,</span> remove<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FieldSet</span></span> <span class="token attr-name">model</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>model<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>li</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>members<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>member-title<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>span</span><span class="token punctuation">></span></span>\n 成员\n <span class="token punctuation">{</span>index <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">}</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>span</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Pop</span></span> <span class="token attr-name">centerArrow</span> <span class="token attr-name">trigger</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>hover<span class="token punctuation">"</span></span> <span class="token attr-name">content</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>删除该成员<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Icon</span></span>\n <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>del-btn<span class="token punctuation">"</span></span>\n <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>close-circle<span class="token punctuation">"</span></span>\n <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>onRemoveClick<span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Pop</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span>\n <span class="token attr-name">model</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>name<span class="token punctuation">}</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>名字:<span class="token punctuation">"</span></span>\n <span class="token attr-name">required</span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormRadioGroupField</span></span> <span class="token attr-name">model</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>sex<span class="token punctuation">}</span></span> <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>性别:<span class="token punctuation">"</span></span> <span class="token attr-name">required</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Radio</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>1<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>男<span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Radio</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Radio</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>2<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>女<span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Radio</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">FormRadioGroupField</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Hobbies</span></span> <span class="token attr-name">model</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>hobbies<span class="token punctuation">}</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>li</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">FieldSet</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">Members</span></span><span class="token punctuation">(</span><span class="token parameter"><span class="token punctuation">{</span> model<span class="token operator">:</span> propsModel <span class="token punctuation">}</span></span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> model <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useFieldArray</span><span class="token punctuation">(</span>propsModel<span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> addOne <span class="token operator">=</span> <span class="token function">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n model<span class="token punctuation">.</span><span class="token method function property-access">push</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>model<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> addTwo <span class="token operator">=</span> <span class="token function">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n model<span class="token punctuation">.</span><span class="token method function property-access">push</span><span class="token punctuation">(</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>model<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> remove <span class="token operator">=</span> <span class="token function">useCallback</span><span class="token punctuation">(</span>\n <span class="token parameter">index</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n model<span class="token punctuation">.</span><span class="token method function property-access">splice</span><span class="token punctuation">(</span>index<span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token punctuation">[</span>model<span class="token punctuation">]</span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">{</span>model<span class="token punctuation">.</span><span class="token property-access">children</span><span class="token punctuation">.</span><span class="token property-access">length</span> <span class="token operator"><</span> <span class="token number">3</span> <span class="token operator">&&</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>addOne<span class="token punctuation">}</span></span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>add-btn<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n 添加一个成员\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">}</span>\n <span class="token punctuation">{</span>model<span class="token punctuation">.</span><span class="token property-access">children</span><span class="token punctuation">.</span><span class="token property-access">length</span> <span class="token operator"><</span> <span class="token number">2</span> <span class="token operator">&&</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>addTwo<span class="token punctuation">}</span></span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>add-btn<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n 添加两个成员\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">}</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>ul</span><span class="token punctuation">></span></span>\n <span class="token punctuation">{</span>model<span class="token punctuation">.</span><span class="token property-access">children</span><span class="token punctuation">.</span><span class="token method function property-access">map</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">child<span class="token punctuation">,</span> index</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">MemberInfo</span></span> <span class="token attr-name">key</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>child<span class="token punctuation">.</span><span class="token property-access">id</span><span class="token punctuation">}</span></span> <span class="token attr-name">model</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>child<span class="token punctuation">}</span></span> <span class="token attr-name">index</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>index<span class="token punctuation">}</span></span> <span class="token attr-name">remove</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>remove<span class="token punctuation">}</span></span> <span class="token punctuation">/></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">}</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>ul</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token keyword">const</span> formBuilder <span class="token operator">=</span> <span class="token function">form</span><span class="token punctuation">(</span><span class="token punctuation">{</span>\n number<span class="token operator">:</span> <span class="token function">field</span><span class="token punctuation">(</span><span class="token string">\'\'</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token method function property-access">validators</span><span class="token punctuation">(</span><span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">required</span><span class="token punctuation">(</span><span class="token string">\'请填写总人数\'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>\n members<span class="token operator">:</span> <span class="token function">array</span><span class="token punctuation">(</span>\n <span class="token function">set</span><span class="token punctuation">(</span><span class="token punctuation">{</span>\n name<span class="token operator">:</span> <span class="token function">field</span><span class="token punctuation">(</span><span class="token string">\'\'</span><span class="token punctuation">)</span>\n <span class="token punctuation">.</span><span class="token method function property-access">validators</span><span class="token punctuation">(</span><span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">required</span><span class="token punctuation">(</span><span class="token string">\'请填写成员名字\'</span><span class="token punctuation">)</span><span class="token punctuation">)</span>\n <span class="token punctuation">.</span><span class="token method function property-access">normalizeBeforeSubmit</span><span class="token punctuation">(</span><span class="token parameter">name</span> <span class="token arrow operator">=></span> name<span class="token punctuation">.</span><span class="token method function property-access">toUpperCase</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>\n sex<span class="token operator">:</span> <span class="token function">field</span><span class="token punctuation">(</span><span class="token string">\'1\'</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token method function property-access">validators</span><span class="token punctuation">(</span>\n <span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">required</span><span class="token punctuation">(</span><span class="token string">\'请选择性别\'</span><span class="token punctuation">)</span>\n <span class="token punctuation">)</span><span class="token punctuation">,</span>\n hobbies<span class="token operator">:</span> <span class="token function">array</span><span class="token punctuation">(</span>\n <span class="token function">field</span><span class="token punctuation">(</span><span class="token string">\'\'</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token method function property-access">validators</span><span class="token punctuation">(</span><span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">required</span><span class="token punctuation">(</span><span class="token string">\'请填写兴趣爱好\'</span><span class="token punctuation">)</span><span class="token punctuation">)</span>\n <span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token method function property-access">defaultValue</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">)</span>\n <span class="token punctuation">)</span><span class="token punctuation">,</span>\n<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">App</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> form <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useForm</span><span class="token punctuation">(</span>formBuilder<span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> <span class="token punctuation">{</span> number<span class="token punctuation">,</span> members <span class="token punctuation">}</span> <span class="token operator">=</span> form<span class="token punctuation">.</span><span class="token property-access">model</span><span class="token punctuation">.</span><span class="token property-access">children</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> setArray <span class="token operator">=</span> <span class="token function">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n form<span class="token punctuation">.</span><span class="token method function property-access">patchValue</span><span class="token punctuation">(</span><span class="token punctuation">{</span>\n number<span class="token operator">:</span> <span class="token number">42</span><span class="token punctuation">,</span>\n members<span class="token operator">:</span> <span class="token punctuation">[</span>\n <span class="token punctuation">{</span>\n name<span class="token operator">:</span> <span class="token string">\'john\'</span><span class="token punctuation">,</span>\n sex<span class="token operator">:</span> <span class="token string">\'1\'</span><span class="token punctuation">,</span>\n hobbies<span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">\'H1\'</span><span class="token punctuation">]</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token punctuation">]</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>form<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword">const</span> getFormValue <span class="token operator">=</span> <span class="token function">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span>form<span class="token punctuation">.</span><span class="token method function property-access">getValue</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>form<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword">const</span> getSubmitValue <span class="token operator">=</span> <span class="token function">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span>form<span class="token punctuation">.</span><span class="token method function property-access">getSubmitValue</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>form<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form</span></span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>demo-form<span class="token punctuation">"</span></span> <span class="token attr-name">layout</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>horizontal<span class="token punctuation">"</span></span> <span class="token attr-name">form</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>form<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormNumberInputField</span></span>\n <span class="token attr-name">model</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>number<span class="token punctuation">}</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>总人数:<span class="token punctuation">"</span></span>\n <span class="token attr-name">required</span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Members</span></span> <span class="token attr-name">model</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>members<span class="token punctuation">}</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">style</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span> marginTop<span class="token operator">:</span> <span class="token number">16</span> <span class="token punctuation">}</span><span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>primary<span class="token punctuation">"</span></span> <span class="token attr-name">htmlType</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>submit<span class="token punctuation">"</span></span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>getFormValue<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n 获取表单值\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>primary<span class="token punctuation">"</span></span> <span class="token attr-name">htmlType</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>submit<span class="token punctuation">"</span></span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>getSubmitValue<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n 获取表单提交值\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>setArray<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>设置 <span class="token maybe-class-name">FieldArray</span> 值<span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Form</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token maybe-class-name">ReactDOM</span><span class="token punctuation">.</span><span class="token method function property-access">render</span><span class="token punctuation">(</span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">App</span></span> <span class="token punctuation">/></span></span><span class="token punctuation">,</span> mountNode<span class="token punctuation">)</span><span class="token punctuation">;</span>'},o.createElement(kn)),o.createElement(Cn,{html:'<h3 class="anchor-heading"><a href="#model-mo-shi-dong-tai-zeng-jia-shan-chu-biao-dan-xiang">¶</a><a href="javascript:void(0)" id="model-mo-shi-dong-tai-zeng-jia-shan-chu-biao-dan-xiang" class="anchor-point"></a>Model 模式动态增加/删除表单项</h3>\n<p>有些联动的场景需要在表单项变化的时候动态删除或者增加表单项,我们提供了一组 API 来支持这类使用场景。</p>\n<p>每个 model 上都有一个 <code>builder</code> 的属性,通过这个属性能够获取到这个 model 对应的 builder 对象,通过 <code>builder.build()</code> 方法就可以可以生成一个行为一样的 model 对象。注意,<code>builder</code> 对象仅在通过上述 <code>Builder</code> API 生成的 model,<code>View</code> 模式下的 model 上这个属性永远是空的。</p>\n<p>除此之外,<code>FieldSetModel</code> 以及 <code>FormModel</code> 上提供了两个方法用来完成子 model 的删除和增加:</p>\n<ul>\n<li><code>removeChild<T extends keyof Children>(name: T): Children[T] | null</code></li>\n<li><code>registerChild(name: string, model: BasicModel): void</code></li>\n</ul>\n<p><code>FieldArrayModel</code> 的 <code>push</code>, <code>unshift</code> 以及 <code>splice</code> 方法也支持直接传入 model。</p>\n<p>由于 <code>FieldArrayModel</code>, <code>FieldSetModel</code> 和 <code>FormModel</code> 子 model 的增删需要触发组件重绘,因此提供了额外的 hook 来处理:</p>\n<ul>\n<li><code>Form.useFieldArrayChildModels</code></li>\n<li><code>Form.useNamedChildModel(parent: FieldSetModel, name: string): BasicModel</code>,注意 <code>FormModel</code> 是 <code>FieldSetModel</code> 的子类,所以也适用于这个方法。</li>\n</ul>\n<p>这两个 hook 不监听子 model 内部状态的变化,如有需要,需使用它们返回的 model 对象自行调用 <code>useField</code> 等 hook 来实现。</p>\n<p>通过结合上述这些能力,就可以完成 <code>Model</code> 模式下表单项的动态增删了。</p>'}),o.createElement(zn,{title:"Model 模式动态增删表单项",id:"Demo22",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span>\n <span class="token maybe-class-name">Form</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Validators</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormRadioGroupField</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormNumberInputField</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormInputField</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Checkbox</span><span class="token punctuation">,</span>\n<span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> merge <span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">\'rxjs\'</span><span class="token punctuation">;</span>\n\n<span class="token keyword">const</span> <span class="token punctuation">{</span> form<span class="token punctuation">,</span> field <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">;</span>\n\n<span class="token keyword">const</span> <span class="token maybe-class-name">ContactType</span> <span class="token operator">=</span> <span class="token punctuation">{</span>\n <span class="token maybe-class-name">Phone</span><span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Email</span><span class="token operator">:</span> <span class="token number">2</span><span class="token punctuation">,</span>\n<span class="token punctuation">}</span><span class="token punctuation">;</span>\n\n<span class="token keyword">const</span> formBuilder <span class="token operator">=</span> <span class="token function">form</span><span class="token punctuation">(</span><span class="token punctuation">{</span>\n contactType<span class="token operator">:</span> <span class="token function">field</span><span class="token punctuation">(</span><span class="token maybe-class-name">ContactType</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">Phone</span></span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token method function property-access">validators</span><span class="token punctuation">(</span>\n <span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">required</span><span class="token punctuation">(</span><span class="token string">\'请选择联系方式\'</span><span class="token punctuation">)</span>\n <span class="token punctuation">)</span><span class="token punctuation">,</span>\n phone<span class="token operator">:</span> <span class="token function">field</span><span class="token punctuation">(</span><span class="token string">\'\'</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token method function property-access">validators</span><span class="token punctuation">(</span>\n <span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">pattern</span><span class="token punctuation">(</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex"><span class="token charclass class-name">\\d</span><span class="token quantifier number">{11}</span></span><span class="token regex-delimiter">/</span></span><span class="token punctuation">,</span> <span class="token string">\'手机号必须是 11 位数字\'</span><span class="token punctuation">)</span>\n <span class="token punctuation">)</span><span class="token punctuation">,</span>\n email<span class="token operator">:</span> <span class="token function">field</span><span class="token punctuation">(</span><span class="token string">\'\'</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token method function property-access">validators</span><span class="token punctuation">(</span><span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">email</span><span class="token punctuation">(</span><span class="token string">\'邮箱不正确\'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>\n<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">App</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> <span class="token punctuation">[</span>preserveState<span class="token punctuation">,</span> setPreserveState<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token maybe-class-name">React</span><span class="token punctuation">.</span><span class="token method function property-access">useState</span><span class="token punctuation">(</span><span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> onPreserveStateChange <span class="token operator">=</span> <span class="token maybe-class-name">React</span><span class="token punctuation">.</span><span class="token method function property-access">useCallback</span><span class="token punctuation">(</span>\n <span class="token parameter">evt</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token function">setPreserveState</span><span class="token punctuation">(</span>evt<span class="token punctuation">.</span><span class="token property-access">target</span><span class="token punctuation">.</span><span class="token property-access">checked</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token punctuation">[</span>setPreserveState<span class="token punctuation">]</span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword">const</span> form <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useForm</span><span class="token punctuation">(</span>formBuilder<span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> removedModelRef <span class="token operator">=</span> <span class="token maybe-class-name">React</span><span class="token punctuation">.</span><span class="token method function property-access">useRef</span><span class="token punctuation">(</span><span class="token keyword null nil">null</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword">const</span> swapModel <span class="token operator">=</span> <span class="token maybe-class-name">React</span><span class="token punctuation">.</span><span class="token method function property-access">useCallback</span><span class="token punctuation">(</span>\n <span class="token punctuation">(</span><span class="token parameter">oldName<span class="token punctuation">,</span> newName</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> prevModel <span class="token operator">=</span> removedModelRef<span class="token punctuation">.</span><span class="token property-access">current</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> oldModel <span class="token operator">=</span> form<span class="token punctuation">.</span><span class="token property-access">model</span><span class="token punctuation">.</span><span class="token method function property-access">removeChild</span><span class="token punctuation">(</span>oldName<span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span>oldModel <span class="token operator">!==</span> <span class="token keyword null nil">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n removedModelRef<span class="token punctuation">.</span><span class="token property-access">current</span> <span class="token operator">=</span> oldModel<span class="token punctuation">;</span>\n <span class="token punctuation">}</span>\n <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>form<span class="token punctuation">.</span><span class="token property-access">model</span><span class="token punctuation">.</span><span class="token method function property-access">get</span><span class="token punctuation">(</span>newName<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> newModel <span class="token operator">=</span> preserveState <span class="token operator">?</span> prevModel <span class="token operator">:</span> prevModel<span class="token punctuation">.</span><span class="token property-access">builder</span><span class="token punctuation">.</span><span class="token method function property-access">build</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n form<span class="token punctuation">.</span><span class="token property-access">model</span><span class="token punctuation">.</span><span class="token method function property-access">registerChild</span><span class="token punctuation">(</span>newName<span class="token punctuation">,</span> newModel<span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token punctuation">[</span>form<span class="token punctuation">,</span> preserveState<span class="token punctuation">]</span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword">const</span> contactTypeValue <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useModelValue</span><span class="token punctuation">(</span>form<span class="token punctuation">.</span><span class="token property-access">model</span><span class="token punctuation">.</span><span class="token method function property-access">get</span><span class="token punctuation">(</span><span class="token string">\'contactType\'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token maybe-class-name">React</span><span class="token punctuation">.</span><span class="token method function property-access">useEffect</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span>contactTypeValue <span class="token operator">===</span> <span class="token maybe-class-name">ContactType</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">Phone</span></span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token function">swapModel</span><span class="token punctuation">(</span><span class="token string">\'email\'</span><span class="token punctuation">,</span> <span class="token string">\'phone\'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span> <span class="token keyword control-flow">else</span> <span class="token punctuation">{</span>\n <span class="token function">swapModel</span><span class="token punctuation">(</span><span class="token string">\'phone\'</span><span class="token punctuation">,</span> <span class="token string">\'email\'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>swapModel<span class="token punctuation">,</span> contactTypeValue<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword">const</span> getFormValue <span class="token operator">=</span> <span class="token maybe-class-name">React</span><span class="token punctuation">.</span><span class="token method function property-access">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span>form<span class="token punctuation">.</span><span class="token method function property-access">getValue</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> form<span class="token punctuation">.</span><span class="token method function property-access">isValid</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>form<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token comment">// `useNamedChildModel` will trigger a render whenever a model is removed or registered</span>\n <span class="token keyword">const</span> phoneModel <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useNamedChildModel</span><span class="token punctuation">(</span>form<span class="token punctuation">.</span><span class="token property-access">model</span><span class="token punctuation">,</span> <span class="token string">\'phone\'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> emailModel <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useNamedChildModel</span><span class="token punctuation">(</span>form<span class="token punctuation">.</span><span class="token property-access">model</span><span class="token punctuation">,</span> <span class="token string">\'email\'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form</span></span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>demo-form<span class="token punctuation">"</span></span> <span class="token attr-name">layout</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>horizontal<span class="token punctuation">"</span></span> <span class="token attr-name">form</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>form<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormRadioGroupField</span></span>\n <span class="token attr-name">model</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>form<span class="token punctuation">.</span><span class="token property-access">model</span><span class="token punctuation">.</span><span class="token method function property-access">get</span><span class="token punctuation">(</span><span class="token string">\'contactType\'</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>联系方式<span class="token punctuation">"</span></span>\n <span class="token attr-name">required</span>\n <span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Radio</span></span> <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token maybe-class-name">ContactType</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">Phone</span></span><span class="token punctuation">}</span></span><span class="token punctuation">></span></span>手机号码<span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Radio</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Radio</span></span> <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token maybe-class-name">ContactType</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">Email</span></span><span class="token punctuation">}</span></span><span class="token punctuation">></span></span>电子邮箱<span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Radio</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">FormRadioGroupField</span></span><span class="token punctuation">></span></span>\n\n <span class="token punctuation">{</span>contactTypeValue <span class="token operator">===</span> <span class="token maybe-class-name">ContactType</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">Phone</span></span> <span class="token operator">&&</span> phoneModel <span class="token operator">&&</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormNumberInputField</span></span>\n <span class="token attr-name">model</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>phoneModel<span class="token punctuation">}</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>手机号码<span class="token punctuation">"</span></span>\n <span class="token attr-name">required</span>\n <span class="token punctuation">/></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">}</span>\n\n <span class="token punctuation">{</span>contactTypeValue <span class="token operator">===</span> <span class="token maybe-class-name">ContactType</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">Email</span></span> <span class="token operator">&&</span> emailModel <span class="token operator">&&</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span> <span class="token attr-name">model</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>emailModel<span class="token punctuation">}</span></span> <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>电子邮箱<span class="token punctuation">"</span></span> <span class="token attr-name">required</span> <span class="token punctuation">/></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">}</span>\n\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">style</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span> marginTop<span class="token operator">:</span> <span class="token number">16</span> <span class="token punctuation">}</span><span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>primary<span class="token punctuation">"</span></span> <span class="token attr-name">htmlType</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>submit<span class="token punctuation">"</span></span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>getFormValue<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n 打印表单值\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Checkbox</span></span>\n <span class="token attr-name">checked</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>preserveState<span class="token punctuation">}</span></span>\n <span class="token attr-name">onChange</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>onPreserveStateChange<span class="token punctuation">}</span></span>\n <span class="token attr-name">style</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span> marginLeft<span class="token operator">:</span> <span class="token number">16</span> <span class="token punctuation">}</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">></span></span>\n 切换联系方式时时保留 model 状态\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Checkbox</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Form</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token maybe-class-name">ReactDOM</span><span class="token punctuation">.</span><span class="token method function property-access">render</span><span class="token punctuation">(</span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">App</span></span> <span class="token punctuation">/></span></span><span class="token punctuation">,</span> mountNode<span class="token punctuation">)</span><span class="token punctuation">;</span>'},o.createElement(rn)),o.createElement(Cn,{html:'<h3 class="anchor-heading"><a href="#biao-dan-zhi-de-ge-shi-hua">¶</a><a href="javascript:void(0)" id="biao-dan-zhi-de-ge-shi-hua" class="anchor-point"></a>表单值的格式化</h3>\n<ul>\n<li>可以通过 <code>normalize</code> 和 <code>format</code> 参数来格式化 <code>Field</code> 的输入输出</li>\n<li>可以通过 <code>normalizeBeforeBlur</code> 方法,在 <code>InputField</code> 等输入框触发 <code>onBlur</code> 事件时修改 <code>model</code> 内的值</li>\n<li>也可以使用 <code>normalizeBeforeSubmit</code> 属性和 <code>form.getSubmitValue()</code> 方法,在不改变 model 内存储值的情况下修改表单提交的值</li>\n</ul>'}),o.createElement(zn,{title:"格式化表单值",id:"Demo11",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> <span class="token maybe-class-name">FormInputField</span><span class="token punctuation">,</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">,</span> <span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">,</span> <span class="token maybe-class-name">Validators</span> <span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">App</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> form <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useForm</span><span class="token punctuation">(</span><span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">View</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form</span></span> <span class="token attr-name">layout</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>horizontal<span class="token punctuation">"</span></span> <span class="token attr-name">form</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>form<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>field1<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>field1<span class="token punctuation">"</span></span>\n <span class="token attr-name">normalizeBeforeBlur</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token parameter">value</span> <span class="token arrow operator">=></span> value<span class="token punctuation">.</span><span class="token method function property-access">trim</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">normalize</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token parameter">value</span> <span class="token arrow operator">=></span> value<span class="token punctuation">.</span><span class="token method function property-access">toUpperCase</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">format</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token parameter">value</span> <span class="token arrow operator">=></span> value<span class="token punctuation">.</span><span class="token method function property-access">toLowerCase</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>label</span><span class="token punctuation">></span></span>实际值:<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>label</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form.FieldValue</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>field1<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Form</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token maybe-class-name">ReactDOM</span><span class="token punctuation">.</span><span class="token method function property-access">render</span><span class="token punctuation">(</span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">App</span></span> <span class="token punctuation">/></span></span><span class="token punctuation">,</span> mountNode<span class="token punctuation">)</span><span class="token punctuation">;</span>'},o.createElement(mn)),o.createElement(Cn,{html:'<h3 class="anchor-heading"><a href="#du-qu-ding-yue-biao-dan-zhi">¶</a><a href="javascript:void(0)" id="du-qu-ding-yue-biao-dan-zhi" class="anchor-point"></a>读取/订阅表单值</h3>\n<p>试想一个使用场景:我们要实现一个活动编辑器,右侧是编辑框,左侧是实时预览;这种场景下除了需要一个地方来输入表单的各个值之外,还需要在另外一个地方读取这些表单值。我们提供了一套统一的简单易用,并且使用姿势和 <code>Field</code> 非常相似的 API 来实现组件值的按需读取。这些组件只会监听所需的数据变化,不会因为没有监听的表单项变化了而产生重绘。</p>\n<ul>\n<li><code>Field</code> 组件对应 <code>FieldValue</code>,<code>View</code> 模式下指定一个 <code>name</code>;<code>Model</code> 模式下指定一个 <code>model</code></li>\n<li><code>FieldSet</code> 组件对应 <code>FieldSetValue</code>,只有一个 <code>name</code> 参数;如果是 <code>Model</code> 模式下已经拿到对应的 model 对象了,那么直接将 <code>model.get(xxx)</code> 传给 <code>FieldValue</code> 组件即可</li>\n<li><code>Form.useFieldArray</code> 对应 <code>useFieldArrayChildModels</code>,<code>View</code> 模式下指定一个 <code>name</code>;<code>Model</code> 模式下指定一个 <code>model</code> 或者 <code>name</code>。注意,它只会监听 <code>children</code> 的增、删行为,不会监听 <code>children</code> 内部的变动</li>\n<li><code>Form.useFieldValue</code> 提供了一种 hooks 的风格来获取表单值(包括 FieldSet、FieldArray、Field),它可以深度监听表单值</li>\n<li><code>Form.useFormValue</code> 提供了一种 hooks 的风格来获取整个表单的值,它可以深度监听表单值</li>\n</ul>'}),o.createElement(zn,{title:"实时预览",id:"Demo12",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span>\n <span class="token maybe-class-name">FormInputField</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Form</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FieldSet</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormControl</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Icon</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Input</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FieldUtils</span><span class="token punctuation">,</span>\n<span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n\n<span class="token keyword">const</span> <span class="token function-variable function"><span class="token maybe-class-name">NicknamesPreview</span></span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> children <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useFieldArrayChildModels</span><span class="token punctuation">(</span><span class="token string">\'nickname\'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>children<span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword control-flow">return</span> <span class="token keyword null nil">null</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span>\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>form-demo-11-preview-nickname<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>label</span><span class="token punctuation">></span></span><span class="token punctuation">{</span><span class="token string">\'昵称:\'</span><span class="token punctuation">}</span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>label</span><span class="token punctuation">></span></span>\n <span class="token punctuation">{</span>children<span class="token punctuation">.</span><span class="token method function property-access">map</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">child<span class="token punctuation">,</span> index</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form.FieldValue</span></span> <span class="token attr-name">key</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>index<span class="token punctuation">}</span></span> <span class="token attr-name">model</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>child<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">{</span><span class="token parameter">value</span> <span class="token arrow operator">=></span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>value<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string"> </span><span class="token template-punctuation string">`</span></span><span class="token punctuation">}</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Form.FieldValue</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">}</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span><span class="token punctuation">;</span>\n\n<span class="token keyword">const</span> <span class="token function-variable function"><span class="token maybe-class-name">Preview</span></span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>form-demo-11-preview<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form.FieldValue</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>name<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token punctuation">{</span><span class="token parameter">value</span> <span class="token arrow operator">=></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>h3</span><span class="token punctuation">></span></span><span class="token punctuation">{</span>value<span class="token punctuation">}</span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>h3</span><span class="token punctuation">></span></span><span class="token punctuation">}</span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Form.FieldValue</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form.FieldSetValue</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>contact<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>form-demo-11-preview-phone<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>label</span><span class="token punctuation">></span></span><span class="token punctuation">{</span><span class="token string">\'电话:\'</span><span class="token punctuation">}</span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>label</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form.FieldValue</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>phone<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>form-demo-11-preview-address<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form.FieldValue</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>address<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Form.FieldSetValue</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">NicknamesPreview</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n<span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n<span class="token keyword">const</span> <span class="token function-variable function"><span class="token maybe-class-name">Nickname</span></span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token parameter"><span class="token punctuation">{</span> model<span class="token operator">:</span> propsModel<span class="token punctuation">,</span> last<span class="token punctuation">,</span> add<span class="token punctuation">,</span> del <span class="token punctuation">}</span></span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> model <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useField</span><span class="token punctuation">(</span>propsModel<span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> onChange <span class="token operator">=</span> <span class="token function">useCallback</span><span class="token punctuation">(</span>\n <span class="token parameter">e</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n model<span class="token punctuation">.</span><span class="token property-access">value</span> <span class="token operator">=</span> e<span class="token punctuation">.</span><span class="token property-access">target</span><span class="token punctuation">.</span><span class="token property-access">value</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token punctuation">[</span>model<span class="token punctuation">]</span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>form-demo-11-nickname<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Input</span></span>\n <span class="token spread"><span class="token punctuation">{</span><span class="token spread operator">...</span><span class="token maybe-class-name">FieldUtils</span><span class="token punctuation">.</span><span class="token method function property-access">useCompositionHandler</span><span class="token punctuation">(</span>model<span class="token punctuation">)</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">onChange</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>onChange<span class="token punctuation">}</span></span>\n <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>model<span class="token punctuation">.</span><span class="token property-access">value</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Icon</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>close-circle<span class="token punctuation">"</span></span> <span class="token attr-name">style</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span> color<span class="token operator">:</span> <span class="token string">\'#da2626\'</span> <span class="token punctuation">}</span><span class="token punctuation">}</span></span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>del<span class="token punctuation">}</span></span> <span class="token punctuation">/></span></span>\n <span class="token punctuation">{</span>last <span class="token operator">&&</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Icon</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>plus-circle<span class="token punctuation">"</span></span> <span class="token attr-name">style</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span> color<span class="token operator">:</span> <span class="token string">\'#4cb35d\'</span> <span class="token punctuation">}</span><span class="token punctuation">}</span></span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>add<span class="token punctuation">}</span></span> <span class="token punctuation">/></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">}</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span><span class="token punctuation">;</span>\n\n<span class="token keyword">const</span> <span class="token function-variable function"><span class="token maybe-class-name">Nicknames</span></span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> model <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useFieldArray</span><span class="token punctuation">(</span><span class="token string">\'nickname\'</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token string">\'\'</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> <span class="token function-variable function">add</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> model<span class="token punctuation">.</span><span class="token method function property-access">push</span><span class="token punctuation">(</span><span class="token string">\'\'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> <span class="token function-variable function">del</span> <span class="token operator">=</span> <span class="token parameter">index</span> <span class="token arrow operator">=></span> model<span class="token punctuation">.</span><span class="token method function property-access">splice</span><span class="token punctuation">(</span>index<span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormControl</span></span> <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>昵称<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">{</span>model<span class="token punctuation">.</span><span class="token property-access">children</span><span class="token punctuation">.</span><span class="token method function property-access">map</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">child<span class="token punctuation">,</span> index</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Nickname</span></span>\n <span class="token attr-name">key</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>index<span class="token punctuation">}</span></span>\n <span class="token attr-name">model</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>child<span class="token punctuation">}</span></span>\n <span class="token attr-name">last</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>model<span class="token punctuation">.</span><span class="token property-access">children</span><span class="token punctuation">.</span><span class="token property-access">length</span> <span class="token operator">===</span> index <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">add</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>add<span class="token punctuation">}</span></span>\n <span class="token attr-name">del</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token function">del</span><span class="token punctuation">(</span>index<span class="token punctuation">)</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">}</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">FormControl</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span><span class="token punctuation">;</span>\n\n<span class="token keyword">const</span> <span class="token function-variable function"><span class="token maybe-class-name">Edit</span></span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span> <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>姓名<span class="token punctuation">"</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>name<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FieldSet</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>contact<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span> <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>电话<span class="token punctuation">"</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>phone<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span> <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>联系地址<span class="token punctuation">"</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>address<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">FieldSet</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Nicknames</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n<span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">App</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> form <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useForm</span><span class="token punctuation">(</span><span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">View</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form</span></span> <span class="token attr-name">form</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>form<span class="token punctuation">}</span></span> <span class="token attr-name">layout</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>horizontal<span class="token punctuation">"</span></span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>form-demo-11<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Preview</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Edit</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Form</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token maybe-class-name">ReactDOM</span><span class="token punctuation">.</span><span class="token method function property-access">render</span><span class="token punctuation">(</span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">App</span></span> <span class="token punctuation">/></span></span><span class="token punctuation">,</span> mountNode<span class="token punctuation">)</span><span class="token punctuation">;</span>'},o.createElement(dn)),o.createElement(zn,{title:"订阅表单值更新",id:"Demo20",src:'<span class="token keyword module">import</span> <span class="token punctuation">{</span>\n <span class="token maybe-class-name">Form</span><span class="token punctuation">,</span>\n <span class="token known-class-name class-name">FormError</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormControl</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Input</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Validators</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FieldSet</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormInputField</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Button</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Notify</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Icon</span><span class="token punctuation">,</span>\n<span class="token punctuation">}</span> <span class="token keyword module">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n\n<span class="token keyword">const</span> <span class="token punctuation">{</span> useState<span class="token punctuation">,</span> useEffect<span class="token punctuation">,</span> useCallback <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token maybe-class-name">React</span><span class="token punctuation">;</span>\n<span class="token keyword">const</span> <span class="token punctuation">{</span> useForm<span class="token punctuation">,</span> useFieldArray<span class="token punctuation">,</span> useFormValue <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">;</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">App</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> form <span class="token operator">=</span> <span class="token function">useForm</span><span class="token punctuation">(</span><span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">View</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form</span></span> <span class="token attr-name">form</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>form<span class="token punctuation">}</span></span> <span class="token attr-name">layout</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>horizontal<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span> <span class="token attr-name">required</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>name<span class="token punctuation">"</span></span> <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>姓名<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>address<span class="token punctuation">"</span></span> <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>地址<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FieldSet</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>stature<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>weight<span class="token punctuation">"</span></span> <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>体重<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>height<span class="token punctuation">"</span></span> <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>身高<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">FieldSet</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FieldArray</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Preview</span></span> <span class="token attr-name">form</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>form<span class="token punctuation">}</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Form</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">FieldArray</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> model <span class="token operator">=</span> <span class="token function">useFieldArray</span><span class="token punctuation">(</span><span class="token string">\'hobbies\'</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token string">\'看书\'</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n model<span class="token punctuation">.</span><span class="token property-access">destroyOnUnmount</span> <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">;</span>\n\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormControl</span></span> <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>爱好<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">{</span>model<span class="token punctuation">.</span><span class="token property-access">children</span><span class="token punctuation">.</span><span class="token method function property-access">map</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">child<span class="token punctuation">,</span> index</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">key</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>child<span class="token punctuation">.</span><span class="token property-access">id</span><span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n <span class="token operator"><</span><span class="token maybe-class-name">FormInputField</span>\n withoutLabel\n model<span class="token operator">=</span><span class="token punctuation">{</span>child<span class="token punctuation">}</span>\n props<span class="token operator">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span>\n addonAfter<span class="token operator">:</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Icon</span></span>\n <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>close<span class="token punctuation">"</span></span>\n <span class="token attr-name">style</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span> cursor<span class="token operator">:</span> <span class="token string">\'pointer\'</span> <span class="token punctuation">}</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> model<span class="token punctuation">.</span><span class="token method function property-access">splice</span><span class="token punctuation">(</span>index<span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">}</span>\n <span class="token operator">/</span><span class="token operator">></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">}</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>primary<span class="token punctuation">"</span></span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> model<span class="token punctuation">.</span><span class="token method function property-access">push</span><span class="token punctuation">(</span><span class="token string">\'\'</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n 增加爱好\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">FormControl</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">Preview</span></span><span class="token punctuation">(</span><span class="token parameter"><span class="token punctuation">{</span> form <span class="token punctuation">}</span></span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token comment">// You will see a warning about performance issues in console.</span>\n <span class="token comment">// Only do this if you know what you are doing.</span>\n <span class="token keyword">const</span> value <span class="token operator">=</span> <span class="token function">useFormValue</span><span class="token punctuation">(</span>form<span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span><span class="token punctuation">></span></span><span class="token maybe-class-name">Form</span> <span class="token maybe-class-name">Value</span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>pre</span><span class="token punctuation">></span></span><span class="token punctuation">{</span><span class="token known-class-name class-name">JSON</span><span class="token punctuation">.</span><span class="token method function property-access">stringify</span><span class="token punctuation">(</span>value<span class="token punctuation">,</span> <span class="token keyword null nil">null</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">}</span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>pre</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token maybe-class-name">ReactDOM</span><span class="token punctuation">.</span><span class="token method function property-access">render</span><span class="token punctuation">(</span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">App</span></span> <span class="token punctuation">/></span></span><span class="token punctuation">,</span> mountNode<span class="token punctuation">)</span><span class="token punctuation">;</span>'},o.createElement(gn)),o.createElement(Cn,{html:"<p>⚠️ 注意:订阅单个表单项的值一般不会有什么问题,但是订阅 <code>FieldArray</code>, <code>FieldSet</code> 或者 <code>Form</code> 的值时需要谨慎,因为这些是容器类型,订阅它们意味着需要订阅它们内部包含的所有表单项的变化,这是一个非常耗资源并且影响性能的操作,所以不推荐大范围频繁使用。针对这个问题,开发模式下会有一个警告信息来提醒使用者。</p>\n<p>当遇到订阅导致重绘次数过多的性能问题时,可以考虑使用 <code>useObservableBatchedEagerState</code> 将操作做批处理,减少重绘次数。</p>\n<p>下面这个示例的场景比较特殊,在 useCallback 的回调中同步触发重绘的话 React 会自动合并无用的重绘;但是如果在异步代码中触发重绘的话 React 并不会自动合并,导致大量重绘操作在短时间内触发,引起性能问题。</p>\n<p>此时可用使用 <code>useObservableBatchedEagerState</code> 来合并 Observable 的修改,从而间接的减少 React 重绘,优化性能。</p>"}),o.createElement(zn,{title:"批处理优化重绘性能",id:"Demo23",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span>\n <span class="token maybe-class-name">Form</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Button</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormInputField</span><span class="token punctuation">,</span>\n useObservableBatchedEagerState<span class="token punctuation">,</span>\n<span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n\n<span class="token keyword">const</span> <span class="token punctuation">{</span> useState<span class="token punctuation">,</span> useCallback <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token maybe-class-name">React</span><span class="token punctuation">;</span>\n\n<span class="token keyword">const</span> formModel <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">form</span><span class="token punctuation">(</span><span class="token punctuation">{</span>\n list<span class="token operator">:</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">array</span><span class="token punctuation">(</span>\n <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">set</span><span class="token punctuation">(</span><span class="token punctuation">{</span>\n v<span class="token operator">:</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">field</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">)</span>\n <span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token method function property-access">defaultValue</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">{</span> v<span class="token operator">:</span> <span class="token number">1</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> v<span class="token operator">:</span> <span class="token number">2</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> v<span class="token operator">:</span> <span class="token number">3</span> <span class="token punctuation">}</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">,</span>\n<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">App</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> form <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useForm</span><span class="token punctuation">(</span>formModel<span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form</span></span> <span class="token attr-name">form</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>form<span class="token punctuation">}</span></span> <span class="token attr-name">layout</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>horizontal<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">List</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Form</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">List</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> model <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useFieldArray</span><span class="token punctuation">(</span><span class="token string">\'list\'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword">const</span> <span class="token punctuation">[</span>batchedListValue<span class="token punctuation">,</span> runInBatchContext<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token function">useObservableBatchedEagerState</span><span class="token punctuation">(</span>\n model<span class="token punctuation">.</span><span class="token property-access">value$</span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span><span class="token string">\'list value change\'</span><span class="token punctuation">,</span> batchedListValue<span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword">const</span> batchUpdate <span class="token operator">=</span> <span class="token function">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token function">setTimeout</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token function">runInBatchContext</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token keyword control-flow">return</span> <span class="token keyword">new</span> <span class="token class-name">Promise</span><span class="token punctuation">(</span><span class="token parameter">resolve</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n model<span class="token punctuation">.</span><span class="token property-access">children</span><span class="token punctuation">.</span><span class="token method function property-access">forEach</span><span class="token punctuation">(</span><span class="token parameter">m</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> vm <span class="token operator">=</span> m<span class="token punctuation">.</span><span class="token method function property-access">get</span><span class="token punctuation">(</span><span class="token string">\'v\'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n vm<span class="token punctuation">.</span><span class="token property-access">value</span> <span class="token operator">=</span> vm<span class="token punctuation">.</span><span class="token property-access">value</span> <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token function">resolve</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>model<span class="token punctuation">,</span> runInBatchContext<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword">const</span> update <span class="token operator">=</span> <span class="token function">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token function">setTimeout</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n model<span class="token punctuation">.</span><span class="token property-access">children</span><span class="token punctuation">.</span><span class="token method function property-access">forEach</span><span class="token punctuation">(</span><span class="token parameter">m</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> vm <span class="token operator">=</span> m<span class="token punctuation">.</span><span class="token method function property-access">get</span><span class="token punctuation">(</span><span class="token string">\'v\'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n vm<span class="token punctuation">.</span><span class="token property-access">value</span> <span class="token operator">=</span> vm<span class="token punctuation">.</span><span class="token property-access">value</span> <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>model<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">{</span>model<span class="token punctuation">.</span><span class="token property-access">children</span><span class="token punctuation">.</span><span class="token method function property-access">map</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">child<span class="token punctuation">,</span> index</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">key</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>child<span class="token punctuation">.</span><span class="token property-access">id</span><span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span> <span class="token attr-name">model</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>child<span class="token punctuation">.</span><span class="token method function property-access">get</span><span class="token punctuation">(</span><span class="token string">\'v\'</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">}</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>batchUpdate<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>批量更新<span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>update<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>逐个更新<span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">Preview</span></span><span class="token punctuation">(</span><span class="token parameter"><span class="token punctuation">{</span> form <span class="token punctuation">}</span></span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token comment">// You will see a warning about performance issues in console.</span>\n <span class="token comment">// Only do this if you know what you are doing.</span>\n <span class="token keyword">const</span> valid <span class="token operator">=</span> <span class="token function">useFormValid</span><span class="token punctuation">(</span>form<span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Alert</span></span> <span class="token attr-name">type</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>valid <span class="token operator">?</span> <span class="token string">\'success\'</span> <span class="token operator">:</span> <span class="token string">\'error\'</span><span class="token punctuation">}</span></span> <span class="token attr-name">style</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span> marginBottom<span class="token operator">:</span> <span class="token number">24</span> <span class="token punctuation">}</span><span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n <span class="token maybe-class-name">Form</span> is <span class="token punctuation">{</span>valid <span class="token operator">?</span> <span class="token string">\'valid\'</span> <span class="token operator">:</span> <span class="token string">\'invalid\'</span><span class="token punctuation">}</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Alert</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token maybe-class-name">ReactDOM</span><span class="token punctuation">.</span><span class="token method function property-access">render</span><span class="token punctuation">(</span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">App</span></span> <span class="token punctuation">/></span></span><span class="token punctuation">,</span> mountNode<span class="token punctuation">)</span><span class="token punctuation">;</span>'},o.createElement(yn)),o.createElement(Cn,{html:'<h3 class="anchor-heading"><a href="#tong-guo-model-ding-yue-shu-ju">¶</a><a href="javascript:void(0)" id="tong-guo-model-ding-yue-shu-ju" class="anchor-point"></a>通过 Model 订阅数据</h3>\n<p><code>useFieldValue</code> 传入 Model 类型参数时不依赖 <code>FormContext</code>,因此也可以在表单外部监听数据变更。\n<code>useModelValue</code> 和 <code>useModelValid</code> 已经废弃,不推荐使用,它们的使用场景就是在表单外部通过 Model 对象订阅数据变化。</p>'}),o.createElement(zn,{title:"通过 Model 订阅数据",id:"Demo21",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">,</span> <span class="token maybe-class-name">FormContext</span><span class="token punctuation">,</span> <span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">,</span> <span class="token maybe-class-name">FormInputField</span> <span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">PreviewName</span></span><span class="token punctuation">(</span><span class="token parameter"><span class="token punctuation">{</span> form <span class="token punctuation">}</span></span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> name <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useFieldValue</span><span class="token punctuation">(</span>form<span class="token punctuation">.</span><span class="token property-access">model</span><span class="token punctuation">.</span><span class="token method function property-access">get</span><span class="token punctuation">(</span><span class="token string">\'name\'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>p</span><span class="token punctuation">></span></span>\n 姓名:\n <span class="token punctuation">{</span>name<span class="token punctuation">}</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>p</span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">Component</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> form <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useForm</span><span class="token punctuation">(</span><span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">View</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form</span></span> <span class="token attr-name">layout</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>horizontal<span class="token punctuation">"</span></span> <span class="token attr-name">form</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>form<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormContext.Provider</span></span>\n <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span>\n labelStyle<span class="token operator">:</span> <span class="token punctuation">{</span> flexBasis<span class="token operator">:</span> <span class="token number">80</span><span class="token punctuation">,</span> justifyContent<span class="token operator">:</span> <span class="token string">\'flex-start\'</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>name<span class="token punctuation">"</span></span> <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>姓名:<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">FormContext.Provider</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Form</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">PreviewName</span></span> <span class="token attr-name">form</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>form<span class="token punctuation">}</span></span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">PreviewName</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token maybe-class-name">ReactDOM</span><span class="token punctuation">.</span><span class="token method function property-access">render</span><span class="token punctuation">(</span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Component</span></span> <span class="token punctuation">/></span></span><span class="token punctuation">,</span> mountNode<span class="token punctuation">)</span><span class="token punctuation">;</span>'},o.createElement(hn)),o.createElement(Cn,{html:'<h3 class="anchor-heading"><a href="#biao-dan-zhi-lian-dong">¶</a><a href="javascript:void(0)" id="biao-dan-zhi-lian-dong" class="anchor-point"></a>表单值联动</h3>'}),o.createElement(zn,{title:"字段值交互",id:"Demo14",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> useEffect <span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">\'react\'</span><span class="token punctuation">;</span>\n<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span>\n <span class="token maybe-class-name">Form</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">NumberInput</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Radio</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Button</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FieldSet</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FieldUtils</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">ValidateOption</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormInputField</span><span class="token punctuation">,</span>\n<span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">App</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> form <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useForm</span><span class="token punctuation">(</span><span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">View</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token function">useEffect</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> field1 <span class="token operator">=</span> form<span class="token punctuation">.</span><span class="token property-access">model</span><span class="token punctuation">.</span><span class="token method function property-access">get</span><span class="token punctuation">(</span><span class="token string">\'field1\'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> field2 <span class="token operator">=</span> form<span class="token punctuation">.</span><span class="token property-access">model</span><span class="token punctuation">.</span><span class="token method function property-access">get</span><span class="token punctuation">(</span><span class="token string">\'field2\'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> $ <span class="token operator">=</span> field1<span class="token punctuation">.</span><span class="token property-access">value$</span><span class="token punctuation">.</span><span class="token method function property-access">subscribe</span><span class="token punctuation">(</span><span class="token parameter">value</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n field2<span class="token punctuation">.</span><span class="token property-access">value</span> <span class="token operator">=</span> value<span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> $<span class="token punctuation">.</span><span class="token method function property-access">unsubscribe</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>form<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form</span></span> <span class="token attr-name">form</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>form<span class="token punctuation">}</span></span> <span class="token attr-name">layout</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>horizontal<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>field1<span class="token punctuation">"</span></span> <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>field1<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>field2<span class="token punctuation">"</span></span> <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>field2<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Form</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token maybe-class-name">ReactDOM</span><span class="token punctuation">.</span><span class="token method function property-access">render</span><span class="token punctuation">(</span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">App</span></span> <span class="token punctuation">/></span></span><span class="token punctuation">,</span> mountNode<span class="token punctuation">)</span><span class="token punctuation">;</span>'},o.createElement(fn)),o.createElement(Cn,{html:'<h3 class="anchor-heading"><a href="#zi-ding-yi-biao-dan-xiang">¶</a><a href="javascript:void(0)" id="zi-ding-yi-biao-dan-xiang" class="anchor-point"></a>自定义表单项</h3>\n<p>实现自定义 <code>Field</code> 的时候会用到这些组件,它们只是样式组件,用来提供和内置 <code>Field</code> 组件一致样式和参数。</p>\n<ul>\n<li><code>Control</code> 封装了 label、自定义组件以及错误信息的结构,<a href="../../apidoc/interfaces/IFormControlProps.html">查看 Props 文档</a></li>\n<li><code>Label</code> 表单项的 label 组件,适用于连 <code>Control</code> 也不想使用的场景,<a href="../../apidoc/interfaces/ILabelProps.html">查看 Props 文档</a></li>\n<li><code>Error</code> 表单项的错误信息组件,同 <code>Label</code> 一样适用于深度自定义的场景,<a href="../../apidoc/interfaces/IFormErrorProps.html">查看 Props 文档</a></li>\n<li><code>useFormChild</code> 使用上述组件时,如果希望支持自动滚动到错误处,需要在组件内使用这个 Hook 关联 model 和 DOM 节点,<a href="../../apidoc/modules.html#useFormChild">查看文档</a></li>\n<li><code>CombineErrors</code> 这个组件用来将多个字段的错误聚合成一个错误展示,需要配合 <code>Field</code> 的 <code>withoutError</code> 参数使用,<a href="../../apidoc/interfaces/ICombineErrorsProps.html">查看 Props 文档</a></li>\n</ul>'}),o.createElement(zn,{title:"自定义表单组件",id:"Demo18",src:'<span class="token keyword module">import</span> <span class="token punctuation">{</span>\n <span class="token maybe-class-name">Form</span><span class="token punctuation">,</span>\n <span class="token known-class-name class-name">FormError</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormControl</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Input</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Validators</span><span class="token punctuation">,</span>\n<span class="token punctuation">}</span> <span class="token keyword module">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">FormIDField</span></span><span class="token punctuation">(</span><span class="token punctuation">{</span>\n name<span class="token punctuation">,</span>\n model<span class="token punctuation">,</span>\n defaultValue <span class="token operator">=</span> <span class="token string">\'\'</span><span class="token punctuation">,</span>\n validators <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>\n label<span class="token punctuation">,</span>\n required<span class="token punctuation">,</span>\n withoutLabel<span class="token punctuation">,</span>\n style<span class="token punctuation">,</span>\n className<span class="token punctuation">,</span>\n<span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span>name <span class="token operator">&&</span> model<span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword control-flow">throw</span> <span class="token keyword">new</span> <span class="token class-name">Error</span><span class="token punctuation">(</span><span class="token string">\'Cannot use name and model together.\'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span>\n <span class="token keyword">const</span> id <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useField</span><span class="token punctuation">(</span>name <span class="token operator">||</span> model<span class="token punctuation">,</span> defaultValue<span class="token punctuation">,</span> <span class="token punctuation">[</span>\n <span class="token spread operator">...</span>validators<span class="token punctuation">,</span>\n <span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">pattern</span><span class="token punctuation">(</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex"><span class="token anchor function">^</span><span class="token charset"><span class="token charset-punctuation punctuation">[</span><span class="token charclass class-name">\\d</span><span class="token charset-punctuation punctuation">]</span></span><span class="token quantifier number">{17}</span><span class="token charset"><span class="token charset-punctuation punctuation">[</span><span class="token charclass class-name">\\d</span>XY<span class="token charset-punctuation punctuation">]</span></span><span class="token anchor function">$</span></span><span class="token regex-delimiter">/</span></span><span class="token punctuation">,</span> <span class="token string">\'请输入合法的身份证号\'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>\n <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword">const</span> onChange <span class="token operator">=</span> <span class="token maybe-class-name">React</span><span class="token punctuation">.</span><span class="token method function property-access">useCallback</span><span class="token punctuation">(</span>\n <span class="token parameter">e</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n id<span class="token punctuation">.</span><span class="token property-access">isTouched</span> <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> value <span class="token operator">=</span> e<span class="token punctuation">.</span><span class="token property-access">target</span><span class="token punctuation">.</span><span class="token property-access">value</span><span class="token punctuation">.</span><span class="token method function property-access">replace</span><span class="token punctuation">(</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex"><span class="token charclass class-name">\\s</span></span><span class="token regex-delimiter">/</span><span class="token regex-flags">g</span></span><span class="token punctuation">,</span> <span class="token string">\'\'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span>value<span class="token punctuation">.</span><span class="token property-access">length</span> <span class="token operator"><=</span> <span class="token number">18</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n id<span class="token punctuation">.</span><span class="token method function property-access">patchValue</span><span class="token punctuation">(</span>value<span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token punctuation">[</span>id<span class="token punctuation">]</span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormControl</span></span>\n <span class="token attr-name">style</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>style<span class="token punctuation">}</span></span>\n <span class="token attr-name">className</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>className<span class="token punctuation">}</span></span>\n <span class="token attr-name">label</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>label<span class="token punctuation">}</span></span>\n <span class="token attr-name">required</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>required<span class="token punctuation">}</span></span>\n <span class="token attr-name">withoutLabel</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>withoutLabel<span class="token punctuation">}</span></span>\n <span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Input</span></span>\n <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token function">formatId</span><span class="token punctuation">(</span>id<span class="token punctuation">.</span><span class="token property-access">value</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">width</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">220</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">onChange</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>onChange<span class="token punctuation">}</span></span>\n <span class="token attr-name">onBlur</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token maybe-class-name">React</span><span class="token punctuation">.</span><span class="token method function property-access">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> id<span class="token punctuation">.</span><span class="token method function property-access">validate</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>id<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormError</span></span><span class="token punctuation">></span></span><span class="token punctuation">{</span>id<span class="token punctuation">.</span><span class="token property-access">error</span><span class="token operator">?.</span>message<span class="token punctuation">}</span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">FormError</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">FormControl</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token keyword">function</span> <span class="token function">formatId</span><span class="token punctuation">(</span><span class="token parameter">value</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> segment <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token number">6</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">,</span> <span class="token number">14</span><span class="token punctuation">,</span> <span class="token number">18</span><span class="token punctuation">]</span><span class="token punctuation">;</span>\n <span class="token keyword">let</span> <span class="token punctuation">{</span> length <span class="token punctuation">}</span> <span class="token operator">=</span> value<span class="token punctuation">;</span>\n <span class="token keyword">let</span> result <span class="token operator">=</span> <span class="token string">\'\'</span><span class="token punctuation">;</span>\n <span class="token keyword">let</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>\n <span class="token keyword control-flow">while</span> <span class="token punctuation">(</span>i <span class="token operator"><</span> length<span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword control-flow">if</span> <span class="token punctuation">(</span>segment<span class="token punctuation">.</span><span class="token method function property-access">includes</span><span class="token punctuation">(</span>i<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n result <span class="token operator">+=</span> <span class="token string">\' \'</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span>\n result <span class="token operator">+=</span> value<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">;</span>\n i<span class="token operator">++</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span>\n <span class="token keyword control-flow">return</span> result<span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">App</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> form <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useForm</span><span class="token punctuation">(</span><span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">View</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form</span></span> <span class="token attr-name">form</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>form<span class="token punctuation">}</span></span> <span class="token attr-name">layout</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>horizontal<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormIDField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>id<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>身份证号:<span class="token punctuation">"</span></span>\n <span class="token attr-name">required</span>\n <span class="token attr-name">validators</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">[</span><span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">required</span><span class="token punctuation">(</span><span class="token string">\'请输入身份证号\'</span><span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Form</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token maybe-class-name">ReactDOM</span><span class="token punctuation">.</span><span class="token method function property-access">render</span><span class="token punctuation">(</span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">App</span></span> <span class="token punctuation">/></span></span><span class="token punctuation">,</span> mountNode<span class="token punctuation">)</span><span class="token punctuation">;</span>'},o.createElement(bn)),o.createElement(zn,{title:"封装多个表单元素",id:"Demo3",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> useCallback<span class="token punctuation">,</span> useMemo <span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">\'react\'</span><span class="token punctuation">;</span>\n<span class="token keyword module">import</span> <span class="token punctuation">{</span>\n <span class="token maybe-class-name">Form</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Select</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">NumberInput</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Notify</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FormControl</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Button</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FieldSet</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FieldUtils</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">Validators</span><span class="token punctuation">,</span>\n <span class="token known-class-name class-name">FormError</span><span class="token punctuation">,</span>\n<span class="token punctuation">}</span> <span class="token keyword module">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n\n<span class="token keyword">const</span> <span class="token punctuation">{</span> <span class="token maybe-class-name">SelectTrigger</span> <span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token maybe-class-name">Select</span><span class="token punctuation">;</span>\n<span class="token keyword">const</span> countyCodeList <span class="token operator">=</span> <span class="token punctuation">[</span>\n <span class="token punctuation">{</span>\n code<span class="token operator">:</span> <span class="token string">\'+86\'</span><span class="token punctuation">,</span>\n zh<span class="token operator">:</span> <span class="token string">\'zhongguo\'</span><span class="token punctuation">,</span>\n eng<span class="token operator">:</span> <span class="token string">\'china\'</span><span class="token punctuation">,</span>\n text<span class="token operator">:</span> <span class="token string">\'中国 +86\'</span><span class="token punctuation">,</span>\n key<span class="token operator">:</span> <span class="token number">0</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token punctuation">{</span>\n code<span class="token operator">:</span> <span class="token string">\'+853\'</span><span class="token punctuation">,</span>\n zh<span class="token operator">:</span> <span class="token string">\'aomen\'</span><span class="token punctuation">,</span>\n eng<span class="token operator">:</span> <span class="token string">\'Macau\'</span><span class="token punctuation">,</span>\n text<span class="token operator">:</span> <span class="token string">\'中国澳门 +853\'</span><span class="token punctuation">,</span>\n key<span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span>\n<span class="token punctuation">]</span><span class="token punctuation">;</span>\n\n<span class="token keyword">const</span> <span class="token function-variable function">filterHandler</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token parameter">item<span class="token punctuation">,</span> keyword</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token keyword control-flow">return</span> <span class="token operator">!</span><span class="token operator">!</span><span class="token punctuation">(</span>\n keyword <span class="token operator">&&</span>\n item<span class="token punctuation">.</span><span class="token property-access">text</span>\n <span class="token punctuation">.</span><span class="token method function property-access">trim</span><span class="token punctuation">(</span><span class="token punctuation">)</span>\n <span class="token punctuation">.</span><span class="token method function property-access">toLowerCase</span><span class="token punctuation">(</span><span class="token punctuation">)</span>\n <span class="token punctuation">.</span><span class="token method function property-access">indexOf</span><span class="token punctuation">(</span>keyword<span class="token punctuation">.</span><span class="token method function property-access">trim</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token method function property-access">toLowerCase</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token operator">></span> <span class="token operator">-</span><span class="token number">1</span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span><span class="token punctuation">;</span>\n\n<span class="token keyword">function</span> <span class="token function">getValue</span><span class="token punctuation">(</span><span class="token parameter">value</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword control-flow">return</span> value<span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token keyword">const</span> <span class="token function-variable function"><span class="token maybe-class-name">ContactPhone</span></span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> select <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useField</span><span class="token punctuation">(</span><span class="token string">\'areacode\'</span><span class="token punctuation">,</span> countyCodeList<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> input <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useField</span><span class="token punctuation">(</span><span class="token string">\'mobile\'</span><span class="token punctuation">,</span> <span class="token string">\'\'</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>\n <span class="token maybe-class-name">Validators</span><span class="token punctuation">.</span><span class="token method function property-access">pattern</span><span class="token punctuation">(</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex"><span class="token anchor function">^</span><span class="token charclass class-name">\\d</span><span class="token quantifier number">{1,10}</span><span class="token anchor function">$</span></span><span class="token regex-delimiter">/</span></span><span class="token punctuation">,</span> <span class="token string">\'请输入正确的手机号\'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>\n <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> onSelectChange <span class="token operator">=</span> <span class="token maybe-class-name">FieldUtils</span><span class="token punctuation">.</span><span class="token method function property-access">useMulti</span><span class="token punctuation">(</span>\n <span class="token function">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n select<span class="token punctuation">.</span><span class="token property-access">isTouched</span> <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>select<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">,</span>\n <span class="token maybe-class-name">FieldUtils</span><span class="token punctuation">.</span><span class="token method function property-access">usePipe</span><span class="token punctuation">(</span>\n getValue<span class="token punctuation">,</span>\n <span class="token maybe-class-name">FieldUtils</span><span class="token punctuation">.</span><span class="token method function property-access">useChangeHandler</span><span class="token punctuation">(</span>select<span class="token punctuation">,</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">ValidateOption</span></span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">Default</span></span><span class="token punctuation">)</span>\n <span class="token punctuation">)</span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> onPhoneNumChange <span class="token operator">=</span> <span class="token maybe-class-name">FieldUtils</span><span class="token punctuation">.</span><span class="token method function property-access">useChangeHandler</span><span class="token punctuation">(</span>\n input<span class="token punctuation">,</span>\n <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">ValidateOption</span></span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">Default</span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormControl</span></span>\n <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>form-demo-multiple-value<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>联系方式:<span class="token punctuation">"</span></span>\n <span class="token attr-name">invalid</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token operator">!</span><span class="token operator">!</span>select<span class="token punctuation">.</span><span class="token property-access">error</span> <span class="token operator">||</span> <span class="token operator">!</span><span class="token operator">!</span>input<span class="token punctuation">.</span><span class="token property-access">error</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Select</span></span>\n <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>areacode<span class="token punctuation">"</span></span>\n <span class="token attr-name">options</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>countyCodeList<span class="token punctuation">}</span></span>\n <span class="token attr-name">filter</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>filterHandler<span class="token punctuation">}</span></span>\n <span class="token attr-name">trigger</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token maybe-class-name">SelectTrigger</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">width</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">160</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>select<span class="token punctuation">.</span><span class="token property-access">value</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">onChange</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>onSelectChange<span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">NumberInput</span></span>\n <span class="token attr-name">style</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span> marginLeft<span class="token operator">:</span> <span class="token number">16</span> <span class="token punctuation">}</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>phone-num<span class="token punctuation">"</span></span>\n <span class="token attr-name">placeholder</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>请填写手机号<span class="token punctuation">"</span></span>\n <span class="token attr-name">width</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token number">160</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>input<span class="token punctuation">.</span><span class="token property-access">value</span><span class="token punctuation">}</span></span>\n <span class="token spread"><span class="token punctuation">{</span><span class="token spread operator">...</span><span class="token maybe-class-name">FieldUtils</span><span class="token punctuation">.</span><span class="token method function property-access">useCompositionHandler</span><span class="token punctuation">(</span>input<span class="token punctuation">)</span><span class="token punctuation">}</span></span>\n <span class="token attr-name">onChange</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>onPhoneNumChange<span class="token punctuation">}</span></span>\n <span class="token attr-name">onBlur</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token function">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n input<span class="token punctuation">.</span><span class="token property-access">isTouched</span> <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">;</span>\n input<span class="token punctuation">.</span><span class="token method function property-access">validate</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>input<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form.CombineErrors</span></span> <span class="token attr-name">models</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">[</span>select<span class="token punctuation">,</span> input<span class="token punctuation">]</span><span class="token punctuation">}</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">FormControl</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span><span class="token punctuation">;</span>\n\n<span class="token keyword">const</span> <span class="token function-variable function"><span class="token maybe-class-name">App</span></span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> form <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useForm</span><span class="token punctuation">(</span><span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">View</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> getFormValues <span class="token operator">=</span> <span class="token function">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> values <span class="token operator">=</span> form<span class="token punctuation">.</span><span class="token method function property-access">getValue</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token console class-name">console</span><span class="token punctuation">.</span><span class="token method function property-access">log</span><span class="token punctuation">(</span>values<span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>form<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> resetForm <span class="token operator">=</span> <span class="token function">useCallback</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span>\n form<span class="token punctuation">.</span><span class="token method function property-access">resetValue</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">[</span>form<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form</span></span> <span class="token attr-name">form</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>form<span class="token punctuation">}</span></span> <span class="token attr-name">layout</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>horizontal<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FieldSet</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>contactPhone<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">ContactPhone</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">FieldSet</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>zent-form__form-actions<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>primary<span class="token punctuation">"</span></span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>getFormValues<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n 获取表单值\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span><span class="token punctuation">{</span><span class="token string">\' \'</span><span class="token punctuation">}</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>primary<span class="token punctuation">"</span></span> <span class="token attr-name">outline</span> <span class="token attr-name">onClick</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>resetForm<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n 重置表单值\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Form</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span><span class="token punctuation">;</span>\n\n<span class="token maybe-class-name">ReactDOM</span><span class="token punctuation">.</span><span class="token method function property-access">render</span><span class="token punctuation">(</span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">App</span></span> <span class="token punctuation">/></span></span><span class="token punctuation">,</span> mountNode<span class="token punctuation">)</span><span class="token punctuation">;</span>'},o.createElement(vn)),o.createElement(zn,{title:"聚合多个字段的错误",id:"Demo10",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> <span class="token maybe-class-name">FormInputField</span><span class="token punctuation">,</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">,</span> <span class="token maybe-class-name">FormStrategy</span> <span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">App</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> form <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useForm</span><span class="token punctuation">(</span><span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">View</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form</span></span> <span class="token attr-name">layout</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>horizontal<span class="token punctuation">"</span></span> <span class="token attr-name">form</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>form<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>field1<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>field1<span class="token punctuation">"</span></span>\n <span class="token attr-name">required</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>请填写内容<span class="token punctuation">"</span></span>\n <span class="token attr-name">helpDesc</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>这个字段不会展示它自己的错误<span class="token punctuation">"</span></span>\n <span class="token attr-name">withoutError</span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span>\n <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>field2<span class="token punctuation">"</span></span>\n <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>field2<span class="token punctuation">"</span></span>\n <span class="token attr-name">required</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>请填写内容<span class="token punctuation">"</span></span>\n <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form.CombineErrors</span></span> <span class="token attr-name">names</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">[</span><span class="token string">\'field1\'</span><span class="token punctuation">,</span> <span class="token string">\'field2\'</span><span class="token punctuation">]</span><span class="token punctuation">}</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Form</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token maybe-class-name">ReactDOM</span><span class="token punctuation">.</span><span class="token method function property-access">render</span><span class="token punctuation">(</span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">App</span></span> <span class="token punctuation">/></span></span><span class="token punctuation">,</span> mountNode<span class="token punctuation">)</span><span class="token punctuation">;</span>'},o.createElement(Fn)),o.createElement(Cn,{html:'<h3 class="anchor-heading"><a href="#form-bu-ju">¶</a><a href="javascript:void(0)" id="form-bu-ju" class="anchor-point"></a><code>Form</code> 布局</h3>\n<p><code>Form</code> 组件使用 <code>flex</code> 布局,有两个参数控制基本的布局结构</p>\n<ul>\n<li><code>layout</code> 控制<strong>表单项内</strong>的布局方式,支持水平 <code>horizontal</code> 和垂直 <code>vertical</code> 两种布局</li>\n<li><code>direction</code> 控制<strong>表单项间</strong>的排列方式,支持 <code>column</code> 和 <code>row</code> 两种排列。</li>\n</ul>\n<p>水平排列通常来说需要设置表单项的<strong>最小宽度</strong>才能正常工作,可以通过 <code>FormContext</code> 中的 <code>controlStyle</code> 来批量设置。</p>'}),o.createElement(zn,{title:"布局",id:"Demo7",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> useState<span class="token punctuation">,</span> useCallback <span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">\'react\'</span><span class="token punctuation">;</span>\n<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">,</span> <span class="token maybe-class-name">Radio</span><span class="token punctuation">,</span> <span class="token maybe-class-name">Notify</span><span class="token punctuation">,</span> <span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">,</span> <span class="token maybe-class-name">FormContext</span> <span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n\n<span class="token keyword">const</span> <span class="token constant">CONTROL_STYLE</span> <span class="token operator">=</span> <span class="token punctuation">{</span> minWidth<span class="token operator">:</span> <span class="token number">270</span> <span class="token punctuation">}</span><span class="token punctuation">;</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">App</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> form <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useForm</span><span class="token punctuation">(</span><span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">View</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> <span class="token punctuation">[</span>layout<span class="token punctuation">,</span> setLayout<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token function">useState</span><span class="token punctuation">(</span><span class="token string">\'vertical\'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> onLayoutChange <span class="token operator">=</span> <span class="token function">useCallback</span><span class="token punctuation">(</span><span class="token parameter">e</span> <span class="token arrow operator">=></span> <span class="token function">setLayout</span><span class="token punctuation">(</span>e<span class="token punctuation">.</span><span class="token property-access">target</span><span class="token punctuation">.</span><span class="token property-access">value</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> <span class="token punctuation">[</span>direction<span class="token punctuation">,</span> setDirection<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token function">useState</span><span class="token punctuation">(</span><span class="token string">\'column\'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword">const</span> onDirectionChange <span class="token operator">=</span> <span class="token function">useCallback</span><span class="token punctuation">(</span><span class="token parameter">e</span> <span class="token arrow operator">=></span> <span class="token function">setDirection</span><span class="token punctuation">(</span>e<span class="token punctuation">.</span><span class="token property-access">target</span><span class="token punctuation">.</span><span class="token property-access">value</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>form-layout<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>form-layout-option<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>span</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>form-layout-option-name<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token maybe-class-name">Layout</span><span class="token operator">:</span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>span</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Radio.Group</span></span> <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>layout<span class="token punctuation">}</span></span> <span class="token attr-name">onChange</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>onLayoutChange<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Radio</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>vertical<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>vertical<span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Radio</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Radio</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>horizontal<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>horizontal<span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Radio</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Radio.Group</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>form-layout-option<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>span</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>form-layout-option-name<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span class="token maybe-class-name">Direction</span><span class="token operator">:</span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>span</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Radio.Group</span></span> <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>direction<span class="token punctuation">}</span></span> <span class="token attr-name">onChange</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>onDirectionChange<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Radio</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>column<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>column<span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Radio</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Radio</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>row<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>row<span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Radio</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Radio.Group</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>hr</span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form</span></span> <span class="token attr-name">layout</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>layout<span class="token punctuation">}</span></span> <span class="token attr-name">direction</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>direction<span class="token punctuation">}</span></span> <span class="token attr-name">form</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>form<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormContext.Provider</span></span> <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span> controlStyle<span class="token operator">:</span> <span class="token constant">CONTROL_STYLE</span> <span class="token punctuation">}</span><span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>name<span class="token punctuation">"</span></span> <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>用户名:<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span><span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>name2<span class="token punctuation">"</span></span> <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>用户名2:<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span><span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>name3<span class="token punctuation">"</span></span> <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>用户名3:<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span><span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">FormContext.Provider</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Form</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>div</span> <span class="token attr-name">className</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>zent-form-demo__form-actions<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Button</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>primary<span class="token punctuation">"</span></span> <span class="token attr-name">htmlType</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>submit<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>\n 获取表单值\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Button</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span>div</span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token maybe-class-name">ReactDOM</span><span class="token punctuation">.</span><span class="token method function property-access">render</span><span class="token punctuation">(</span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">App</span></span> <span class="token punctuation">/></span></span><span class="token punctuation">,</span> mountNode<span class="token punctuation">)</span><span class="token punctuation">;</span>'},o.createElement(wn)),o.createElement(Cn,{html:'<h3 class="anchor-heading"><a href="#biao-dan-shang-xia-wen">¶</a><a href="javascript:void(0)" id="biao-dan-shang-xia-wen" class="anchor-point"></a>表单上下文</h3>\n<p>使用<code>FormContext</code>对整个表单的行为进行控制,目前支持对 <code>Label</code> 组件以及 <code>Control</code> 组件进行样式自定义。</p>\n<pre><code class="language-ts"><span class="token keyword">interface</span> <span class="token class-name">IZentFormContext</span> <span class="token punctuation">{</span>\n labelStyle<span class="token operator">?</span><span class="token operator">:</span> CSSProperties<span class="token punctuation">;</span>\n controlStyle<span class="token operator">?</span><span class="token operator">:</span> CSSProperties<span class="token punctuation">;</span>\n<span class="token punctuation">}</span></code></pre>'}),o.createElement(zn,{title:"表单上下文",id:"Demo17",src:'<span class="token keyword module">import</span> <span class="token imports"><span class="token punctuation">{</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">,</span> <span class="token maybe-class-name">FormContext</span><span class="token punctuation">,</span> <span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">,</span> <span class="token maybe-class-name">FormInputField</span> <span class="token punctuation">}</span></span> <span class="token keyword module">from</span> <span class="token string">\'zent\'</span><span class="token punctuation">;</span>\n\n<span class="token keyword">function</span> <span class="token function"><span class="token maybe-class-name">Component</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>\n <span class="token keyword">const</span> form <span class="token operator">=</span> <span class="token maybe-class-name">Form</span><span class="token punctuation">.</span><span class="token method function property-access">useForm</span><span class="token punctuation">(</span><span class="token maybe-class-name">FormStrategy</span><span class="token punctuation">.</span><span class="token property-access"><span class="token maybe-class-name">View</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>\n <span class="token keyword control-flow">return</span> <span class="token punctuation">(</span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Form</span></span> <span class="token attr-name">layout</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>horizontal<span class="token punctuation">"</span></span> <span class="token attr-name">form</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span>form<span class="token punctuation">}</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormContext.Provider</span></span>\n <span class="token attr-name">value</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span> labelStyle<span class="token operator">:</span> <span class="token punctuation">{</span> flexBasis<span class="token operator">:</span> <span class="token number">80</span><span class="token punctuation">,</span> justifyContent<span class="token operator">:</span> <span class="token string">\'flex-start\'</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token punctuation">}</span></span>\n <span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>name<span class="token punctuation">"</span></span> <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>姓名:<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">FormInputField</span></span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>contact<span class="token punctuation">"</span></span> <span class="token attr-name">label</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>联系方式:<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">FormContext.Provider</span></span><span class="token punctuation">></span></span>\n <span class="token tag"><span class="token tag"><span class="token punctuation"></</span><span class="token class-name">Form</span></span><span class="token punctuation">></span></span>\n <span class="token punctuation">)</span><span class="token punctuation">;</span>\n<span class="token punctuation">}</span>\n\n<span class="token maybe-class-name">ReactDOM</span><span class="token punctuation">.</span><span class="token method function property-access">render</span><span class="token punctuation">(</span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span><span class="token class-name">Component</span></span> <span class="token punctuation">/></span></span><span class="token punctuation">,</span> mountNode<span class="token punctuation">)</span><span class="token punctuation">;</span>'},o.createElement(xn)),o.createElement(Cn,{html:'<h3 class="anchor-heading"><a href="#fieldutils">¶</a><a href="javascript:void(0)" id="fieldutils" class="anchor-point"></a><code>FieldUtils</code></h3>\n<p><code>FieldUtils</code> 提供了一些有用的工具函数,如果不知道干什么用的或者看不懂,说明你没有需求,不需要用到它们,这些工具本身定位就是高级用法。</p>\n<ul>\n<li>useMulti 用来按顺序调用一批函数,只使用它们的副作用,忽略返回值,<a href="../../apidoc/modules/FieldUtils.html#useMulti">查看函数定义</a></li>\n<li>usePipe 用来从左往右按顺序调用一批函数,上一个函数的返回值作为下一个函数的参数,返回最后一个函数的返回值,<a href="../../apidoc/modules/FieldUtils.html#usePipe">查看函数定义</a></li>\n<li>useCompositionHandler 用来在 <code>model</code> 上维护一个输入法编辑的状态, <code>model.isCompositing</code>,<a href="../../apidoc/modules/FieldUtils.html#useCompositionHandler">查看函数定义</a>。组件内部会根据这个状态在输入法输入阶段跳过校验</li>\n<li>useChangeHandler 生成一个 <code>onChange</code> 回调函数,具体说明请<a href="../../apidoc/modules/FieldUtils.html#useChangeHandler">查看函数定义</a></li>\n<li>compose 与 usePipe 类似,区别是 usePipe 作为 hook 使用,而 compose 可以用在任何地方,例如组合多个校验函数中间件,<a href="../../apidoc/modules/FieldUtils.html#compose">查看函数定义</a></li>\n</ul>'}))}}},82010:(n,a,s)=>{"use strict";s.d(a,{b:()=>r});var t=s(59312),p=s(24246),o=s(60042),e=s.n(o),c=s(27378),l=s(78486),u=s(78513),k=["outline","closed","onClose"],i=["title","description","loading","closable","closed","onClose","closeContent","extraContent"],r=function(n){function a(){var a=null!==n&&n.apply(this,arguments)||this;return a.state={closed:!1},a.onCloseHandler=function(){a.isControlled||a.setState({closed:!0}),a.props.onClose&&a.props.onClose()},a}return(0,t.ZT)(a,n),Object.defineProperty(a.prototype,"isControlled",{get:function(){return"closed"in this.props},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"closed",{get:function(){return this.isControlled?this.props.closed:this.state.closed},enumerable:!1,configurable:!0}),a.prototype.render=function(){var n;if(this.closed)return null;var a=(0,u.Z)(this.props,i),s=a.className,o=a.type,c=a.outline,r=(0,t._T)(a,["className","type","outline"]),m=(0,u.Z)(this.props,k),d=e()("zent-alert","zent-alert-style-"+o,s,((n={})["zent-alert-outline"]=c,n));return(0,p.jsx)("div",(0,t.pi)({className:d},r,{"data-zv":"9.12.16"},{children:(0,p.jsx)(l.Z,(0,t.pi)({},m,{onAlertItemClose:this.onCloseHandler},{children:this.props.children}),void 0)}),void 0)},a.highlightClassName="zent-alert-content__highlight",a.defaultProps={type:"info",loading:!1,outline:!1,closable:!1},a}(c.PureComponent)},78486:(n,a,s)=>{"use strict";var t=s(59312),p=s(24246),o=s(27378),e=s(60042),c=s.n(e),l=s(27036),u=s(20840),k={info:"info-circle",warning:"warning",success:"check-circle",error:"error-circle"},i=(0,o.forwardRef)((function(n,a){var s=n.extraContent,e=n.classItemName,i=n.title,r=n.description,m=n.children,d=n.loading,g=n.type,y=n.closable,h=n.closeContent,f=n.onAlertItemClose,b=(0,o.useRef)(n);b.current=n;var v=(0,o.useMemo)((function(){return m||(0,p.jsxs)(p.Fragment,{children:[i&&(0,p.jsx)("h3",(0,t.pi)({className:"zent-alert-item-content__title","data-zv":"9.12.16"},{children:i}),void 0),r&&(0,p.jsx)("p",(0,t.pi)({className:"zent-alert-item-content__description","data-zv":"9.12.16"},{children:r}),void 0)]},void 0)}),[m,r,i]),F=(0,o.useMemo)((function(){var n=b.current.onClose;return y?(0,p.jsx)("div",(0,t.pi)({className:"zent-alert-item-close-wrapper",onClick:function(a){null==n||n(),f&&f(),a.stopPropagation()},"data-zv":"9.12.16"},{children:null!=h?h:(0,p.jsx)(l.Z,{type:"close",className:"zent-alert-item-close-btn"},void 0)}),void 0):null}),[y,h,f]),w=(0,o.useMemo)((function(){return d?(0,p.jsx)(u.Z,{className:"zent-alert-item-icon",loading:!0,icon:"circle",iconSize:16},void 0):g in k?(0,p.jsx)(l.Z,{className:"zent-alert-item-icon",type:k[g]},void 0):null}),[d,g]);return(0,p.jsxs)("div",(0,t.pi)({className:c()("zent-alert-item",e),ref:a,"data-zv":"9.12.16"},{children:[w,(0,p.jsx)("div",(0,t.pi)({className:"zent-alert-item-content","data-zv":"9.12.16"},{children:v}),void 0),s&&(0,p.jsx)("div",(0,t.pi)({className:"zent-alert-item-extra-content","data-zv":"9.12.16"},{children:s}),void 0),F]}),void 0)}));i.displayName="AlertItem",a.Z=i}}]);