表单开发包括:布局、验证、加载、提交、清除、重置等。
效果图如下:
[img]http://www.miniui.com/docs/quickstart/images/form.gif[/img]
[b]表单布局[/b]
使用HTML Table标签实现任意丰富的表单布局:
<table class="form-table" border="0" cellpadding="1" cellspacing="2">
<tr>
<td class="form-label" style="width:60px;">姓名:</td>
<td style="width:150px">
<input name="name" class="mini-textbox" />
</td>
<td class="form-label" style="width:60px;">地址:</td>
<td style="width:150px">
<input name="addr" class="mini-textbox" />
</td>
</tr>
<tr>
<td class="form-label">性别:</td>
<td >
<input name="gender" class="mini-radiobuttonlist" data="[{id: 1, text: '男'}, {id: 2, text: '女'}]"/>
</td>
<td class="form-label">年龄:</td>
<td >
<input name="age" class="mini-spinner" />
</td>
</tr>
<tr>
<td class="form-label">备注:</td>
<td colspan="3" >
<input name="remarks" class="mini-textarea" style="width:343px;height:60px;"/>
</td>
</tr>
</table>
[b]数据验证[/b]
监听处理控件的"validation"事件,自定义验证规则和错误描述信息:
<input id="username" name="username"
onvalidation="onUserNameValidation" class="mini-textbox" required="true" />
function onUserNameValidation(e) {
if (e.isValid) {
if (isEmail(e.value) == false) {
e.errorText = "必须输入邮件地址";
e.isValid = false;
}
}
}
使用mini.Form组件对多个控件进行验证:
var form = new mini.Form("#form1");
form.validate();
[b]加载表单[/b]
$.ajax({
url: "../data/FormService.aspx?method=LoadData",
type: "post",
success: function (text) {
var data = mini.decode(text); //反序列化成对象
form.setData(data); //设置多个控件数据
}
});
[b]提交表单[/b]
//提交表单数据
var form = new mini.Form("#form1");
var data = form.getData(); //获取表单多个控件的数据
var json = mini.encode(data); //序列化成JSON
$.ajax({
url: "../data/FormService.aspx?method=SaveData",
type: "post",
data: { submitData: json },
success: function (text) {
alert("提交成功,返回结果:" + text);
}
});
[b]清除表单[/b]
form.clear();
[b]重置表单[/b]
form.reset();
参考示例:
[url=http://www.miniui.com/demo/formlayout/formlayout.html]表单布局[/url]
[url=http://www.miniui.com/demo/form/form.html]表单控件[/url]
[url=http://www.miniui.com/demo/datagrid/popupeditform.html]弹出面板:本页面[/url]
[url=http://www.miniui.com/demo/datagrid/datagrid.html]弹出面板:子页面[/url]
[url=http://www.miniui.com/demo/datagrid/editform.html]编辑表单:行内编辑[/url]
[url=http://www.miniui.com/demo/form/rules.html]验证规则[/url]
[url=http://www.miniui.com/demo/form/validation.html]表单:验证[/url]
[url=http://www.miniui.com/demo/form/validLabel.html]表单:文本显示[/url]
[url=http://www.miniui.com/demo/form/validGroup.html]表单:组合验证[/url]
[url=http://www.miniui.com/demo/form/validWindow.html]表单:弹出框验证[/url]
效果图如下:
[img]http://www.miniui.com/docs/quickstart/images/form.gif[/img]
[b]表单布局[/b]
使用HTML Table标签实现任意丰富的表单布局:
<table class="form-table" border="0" cellpadding="1" cellspacing="2">
<tr>
<td class="form-label" style="width:60px;">姓名:</td>
<td style="width:150px">
<input name="name" class="mini-textbox" />
</td>
<td class="form-label" style="width:60px;">地址:</td>
<td style="width:150px">
<input name="addr" class="mini-textbox" />
</td>
</tr>
<tr>
<td class="form-label">性别:</td>
<td >
<input name="gender" class="mini-radiobuttonlist" data="[{id: 1, text: '男'}, {id: 2, text: '女'}]"/>
</td>
<td class="form-label">年龄:</td>
<td >
<input name="age" class="mini-spinner" />
</td>
</tr>
<tr>
<td class="form-label">备注:</td>
<td colspan="3" >
<input name="remarks" class="mini-textarea" style="width:343px;height:60px;"/>
</td>
</tr>
</table>
[b]数据验证[/b]
监听处理控件的"validation"事件,自定义验证规则和错误描述信息:
<input id="username" name="username"
onvalidation="onUserNameValidation" class="mini-textbox" required="true" />
function onUserNameValidation(e) {
if (e.isValid) {
if (isEmail(e.value) == false) {
e.errorText = "必须输入邮件地址";
e.isValid = false;
}
}
}
使用mini.Form组件对多个控件进行验证:
var form = new mini.Form("#form1");
form.validate();
[b]加载表单[/b]
$.ajax({
url: "../data/FormService.aspx?method=LoadData",
type: "post",
success: function (text) {
var data = mini.decode(text); //反序列化成对象
form.setData(data); //设置多个控件数据
}
});
[b]提交表单[/b]
//提交表单数据
var form = new mini.Form("#form1");
var data = form.getData(); //获取表单多个控件的数据
var json = mini.encode(data); //序列化成JSON
$.ajax({
url: "../data/FormService.aspx?method=SaveData",
type: "post",
data: { submitData: json },
success: function (text) {
alert("提交成功,返回结果:" + text);
}
});
[b]清除表单[/b]
form.clear();
[b]重置表单[/b]
form.reset();
参考示例:
[url=http://www.miniui.com/demo/formlayout/formlayout.html]表单布局[/url]
[url=http://www.miniui.com/demo/form/form.html]表单控件[/url]
[url=http://www.miniui.com/demo/datagrid/popupeditform.html]弹出面板:本页面[/url]
[url=http://www.miniui.com/demo/datagrid/datagrid.html]弹出面板:子页面[/url]
[url=http://www.miniui.com/demo/datagrid/editform.html]编辑表单:行内编辑[/url]
[url=http://www.miniui.com/demo/form/rules.html]验证规则[/url]
[url=http://www.miniui.com/demo/form/validation.html]表单:验证[/url]
[url=http://www.miniui.com/demo/form/validLabel.html]表单:文本显示[/url]
[url=http://www.miniui.com/demo/form/validGroup.html]表单:组合验证[/url]
[url=http://www.miniui.com/demo/form/validWindow.html]表单:弹出框验证[/url]