codecamp

React EasyUI 表单

表单( Form )提供多种方法来执行带有表单字段的动作。 表单( Form )可调用validate方法以检查表单是否有效。

属性列表

名称 数据类型 作用描述 默认值
model Object 表单数据。 null
rules Object 验证规则。 null
delay number 延迟验证上次输入值。 200

  • rules 属性代码示例:

rules: {
    name: ["required", "length[5,10]"],
    email: "email",
    hero: "required",
    addr: {
        "required":true,
        "myrule":{
            "validator": (value) => {
                if (...){
                    return true;
                } else {
                    return Promise(resolve => {
                        //...
                        resolve(true);
                    });
                }
            },
            "message": "my error message."
        }
    }
}

事件列表

名称 参数 作用描述
onValidate errors 验证字段时触发。
onChange name,value 验证字段时触发。
onSubmit event 提交表单时触发。

方法列表

名称 参数 返回值 作用描述
validate none void 验证所有表单规则。
validateField name void 验证指定字段的规则。

注:
- 继承: LocaleBase 。

使用方法

<Form model={user} onChange={this.handleChange.bind(this)}>
  <div style={{ marginBottom: '20px' }}>
    <Label htmlFor="name" align="top">Name:</Label>
    <TextBox inputId="name" name="name" value={user.name}></TextBox>
        </div>
        <div style={{ marginBottom: '20px' }}>
        <Label htmlFor="email" align="top">Email:</Label>
        <TextBox inputId="email" name="email" value={user.email}></TextBox>
    </div>
    <div style={{ marginBottom: '20px' }}>
    <Label htmlFor="hero" align="top">Select a hero:</Label>
    <ComboBox inputId="hero" data={heroes} name="hero" value={user.hero}></ComboBox>
</div>
<div style={{ marginBottom: '20px' }}>
<CheckBox inputId="accept" name="accept" checked={user.accept}></CheckBox>
<Label htmlFor="accept" style={{width:100}}>Accept Me</Label>
</div>
<div style={{ marginBottom: '20px' }}>
<LinkButton onClick={this.handleSubmit.bind(this)}>Submit</LinkButton>
</div>
</Form>
React EasyUI 分页
React EasyUI 下拉列表框
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

React EasyUI 教程总览

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }