# formlite
A React component for building validation forms
Inspire Copy by react-jsonschema-form
Options
属性 | 描述 | 可选值类型 |
---|---|---|
label | 标题 | string |
description | 描述 | string |
required | 是否必填 | boolean |
initialValue | 初始值 | any |
validator | 验证 | function(value, callback){} |
- | - | [{pattern:/.{5,10}/, message: '长度必须是5到10位'}, ...] |
Input.js
;{ return <input value=value onChange= ...others/>;}InputdisplayName = 'Input';
FormRenderer.js
;Component { let label help required description children validating error decorator = thisprops; let className = error?'error':'success'; return <div className="form-renderer"> <label className=`label `>label</label> <div className="decorator"> React <div className="error-text">error</div> </div> /*decorator?decorator(children):children*/ validating && 'validating……' </div> ; }
Usage
常用
;;;; FormLite; // 注册可用的组件FormLite; // 设置表单渲染模板默认值FormLite; // 设置表单值变化时验证模式, ALL: 自动验证所有值, ITEM: 只验证当前修改值, NONE: 不自动验证 @FormLiteComponent { console; thispropsform; return true; }; { let Input DatePicker = thispropsform; return <div> <Input name="a" style=color: 'blue'/> <Input name="b"/> <Input name="c"/> <Input name="c" style=color: 'blue' readOnly/> <DatePicker name="d" onChange=thisonDateChange/> <button onClick=thisonSubmit>submit</button> <button onClick=thisonReset>reset</button> </div> ; }
create
;@FormLiteComponent { // …… }
Functions
;@FormLiteComponent { thispropsform; // 注册私有组件 thispropsform; // 注册私有表单渲染模板 thispropsform; // 设置私有验证模式 thispropsform // 设置默认值 thispropsform; } { // …… }