Form 表单
具有数据收集、校验和提交功能的表单,包含复选框、单选框、输入框、下拉选择框等元素。
表单
我们为 form
提供了以下两种排列方式:
- 水平排列:
.ant-form-horizontal
类可以实现 label
标签和表单控件的水平排列;
- 行内排列:
.ant-form-inline
类可使其表现为 inline-block 级别的控件。
表单域
表单一定会包含表单域,表单域可以是输入控件,标准表单域,标签,下拉菜单,文本域等。
在这里,我们使用 .ant-form-item
类来表示表单域,它包含了一个标签和一个输入控件。
为了获得更好的排列,请将 label
标签和 <input>
、<textarea>
、<select>
控件包裹在 .ant-form-item
中。
组件演示
禁用的表单控件
<form class="ant-form-horizontal">
<div class="ant-form-item">
<label class="col-5">禁用的输入框:</label>
<div class="col-12">
<input class="ant-input" type="text" value="我是禁用的" disabled>
</div>
</div>
</form>
禁用的 fieldset
<form class="ant-form-horizontal">
<fieldset disabled>
<div class="ant-form-item ant-form-item-compact">
<label for="userName" class="col-5" required>用户名:</label>
<div class="col-12">
<p class="ant-form-text">大眼萌 minion</p>
</div>
</div>
<div class="ant-form-item">
<label for="password" class="col-5" required>密码:</label>
<div class="col-12">
<input class="ant-input" type="password" id="password" value="123456"/>
</div>
</div>
<div class="row">
<div class="col-12 col-offset-5">
<input type="submit" class="ant-btn ant-btn-primary" value="确 定" />
</div>
</div>
</fieldset>
</form>
不带反馈图标的校验提示
带图标的校验提示(水平排列的表单)
<h4>不带反馈图标的校验提示</h4>
<br />
<form class="ant-form-horizontal">
<div class="ant-form-item has-error">
<label for="error" class="col-5">失败校验:</label>
<div class="col-12">
<input class="ant-input" type="text" id="error" value="无效选择"/>
<div class="ant-form-explain">请输入数字和字母组合</div>
</div>
</div>
<div class="ant-form-item has-warning">
<label for="warning" class="col-5">警告校验:</label>
<div class="col-12">
<input class="ant-input" type="text" id="warning" value="前方高能预警"/>
</div>
</div>
</form>
<h4>带图标的校验提示(水平排列的表单)</h4>
<br />
<form class="ant-form-horizontal">
<div class="ant-form-item">
<label class="col-5" for="validating">校验中:</label>
<div class="col-12">
<div class="has-feedback is-validating">
<input class="ant-input" type="text" id="validating" value="我是被校验的内容"/>
<div class="ant-form-explain">信息审核中...</div>
</div>
</div>
</div>
<div class="ant-form-item">
<label class="col-5" for="input1">成功校验:</label>
<div class="col-12">
<div class="has-feedback has-success">
<input class="ant-input" type="text" id="input1" value="我是正文"/>
</div>
</div>
</div>
<div class="ant-form-item">
<label class="col-5" for="input2">失败校验:</label>
<div class="col-12">
<div class="has-feedback has-error">
<input class="ant-input" type="text" id="input2" value="无效选择"/>
<div class="ant-form-explain">请输入数字和字母组合</div>
</div>
</div>
</div>
<div class="ant-form-item">
<label class="col-5" for="input3">警告校验:</label>
<div class="col-12">
<div class="has-feedback has-warning">
<input class="ant-input" type="text" id="input3" value="前方高能预警"/>
</div>
</div>
</div>
</form>
var Select = antd.Select;
var Option = Select.Option;
var InputNumber = antd.InputNumber;
var Datepicker = antd.Datepicker;
var Switch = antd.Switch;
var Menu = antd.Menu;
var Dropdown = antd.Dropdown;
var Slider = antd.Slider;
var menu = <Menu>
<Menu.Item>
<a target="_blank" href="http://www.alipay.com/">.net</a>
</Menu.Item>
<Menu.Item>
<a target="_blank" href="http://www.taobao.com/">.jp</a>
</Menu.Item>
<Menu.Item>
<a target="_blank" href="http://www.tmall.com/">.org</a>
</Menu.Item>
</Menu>;
function handleSelectChange(value) {
console.log('selected ' + value);
}
function onInputNumberChange(v){
console.log('changed',v);
}
React.render(
<form className="ant-form-horizontal">
<div className="ant-form-item">
<label className="col-8" required>InputNumber 数字输入框:</label>
<div className="col-10">
<InputNumber size="large" min={1} max={10} defaultValue={3} onChange={onInputNumberChange} style={{width:100}}/>
<span className="ant-form-text"> 台机器</span>
</div>
</div>
<div className="ant-form-item ant-form-item-compact">
<label className="col-8" required>
<i className="anticon anticon-exclamation-circle" style={{color: '#f60'}}></i> 我是标题:
</label>
<div className="col-10">
<p className="ant-form-text">唧唧复唧唧木兰当户织呀</p>
<p className="ant-form-text">
<a href="javascript:;">链接文字</a>
</p>
</div>
</div>
<div className="ant-form-item">
<label htmlFor="" className="col-8" required>Switch 开关:</label>
<div className="col-10">
<Switch />
</div>
</div>
<div className="ant-form-item">
<label htmlFor="" className="col-8" required>Slider 滑动输入条:</label>
<div className="col-10">
<Slider marks={["A","B","C","D","E","F","G"]} />
</div>
</div>
<div className="ant-form-item">
<label htmlFor="" className="col-8" required>Select 选择器:</label>
<div className="col-16">
<Select size="large" defaultValue="lucy" style={{width:200}} onChange={handleSelectChange}>
<Option value="jack">jack</Option>
<Option value="lucy">lucy</Option>
<Option value="disabled" disabled>disabled</Option>
<Option value="yiminghe">yiminghe</Option>
</Select>
</div>
</div>
<div className="ant-form-item">
<label htmlFor="" className="col-8" required>Datepicker 日期选择框:</label>
<div className="col-6">
<Datepicker />
</div>
<div className="col-1">
<p className="ant-form-split">-</p>
</div>
<div className="col-6">
<Datepicker />
</div>
</div>
<div className="ant-form-item has-error">
<label htmlFor="" className="col-8" required>Datepicker 校验:</label>
<div className="col-6">
<Datepicker />
</div>
<div className="col-1">
<p className="ant-form-split">-</p>
</div>
<div className="col-6">
<Datepicker />
</div>
<div className="col-19 col-offset-8">
<p className="ant-form-explain">请输入正确选项</p>
</div>
</div>
</form>
, document.getElementById('components-form-demo-mix'));