在开发中常常有必填字段,
<span style="color:Red">*</span>服务地址:</td>
<hy:formfield name="address" required="true"
title="服务地址" maxlength="255" οnchange="validAddress()" />
<label id="validAddr"></label>
我们设置为required="true",通过d设置ajaxform1.isValid() && ajaxform2.isValid()来判断是否对必填字段进行填写
对填写字段是否符合格式通过onchange事件监听οnchange="validAddress()",
function validAddress() {
var addr = ajaxform2.getColumnValue("address");
$.request({
action : "validAddress",
params : {
addr : addr
},
success : validInfo
});
}
请求的Action:
public void validAddress() {
String proPrefix = IntegrationConfig.getConfig().getWsProviderPrefix();
String disPrefix = IntegrationConfig.getConfig().getWsDispatchPrefix();
if ((this.addr.contains(proPrefix)) || (this.addr.contains(disPrefix)))
this.responseData.setParameter("valid", "false");
else
this.responseData.setParameter("valid", "true");
}
回调函数:
function validInfo(response) {
if ("false" == response.getParameter("valid")) {
$("#validAddr").empty();
$("#validAddr").append(
"<span id='labelId' style='color:Red;'>服务地址不正确</span>");
} else {
$("#validAddr").empty();
}
}