我有一个带有某些字段的简单表单,我只想在客户端验证我的字段,所以我正在使用并且它可以处理模糊事件
问题是当我提交表单错误消息并提交表单时
我正在尝试对表单提交进行验证,但是我怎么知道哪个验证失败了
<aui:form name="myForm" action="<%=uploadPromotionURL %>" method="post" enctype="multipart/form-data">
<aui:input name="promotionName" label="Promotion Name">
<aui:validator name="required" errorMessage="This field can not be empty"/>
</aui:input>
<aui:input name="promotionDesc" label="Promotion Description"/>
<aui:input type="file" name="offerImages" label="Promotion Image" multiple="multiple" accept="image/*" onchange="setUploadSize(this)">
<aui:validator name="acceptFiles">'jpg,png,tif,gif,jpeg'</aui:validator>
<aui:validator name="required" errorMessage="Please chhose offer"/>
<aui:validator name="custom" errorMessage="File size should not be more than 5Mb">
function(val,node,junction){
if(uploadSize==true){
return true;
}else{
return false;
}
}
</aui:validator>
</aui:input>
<aui:select label="Promotion Assignment" id="promotionAssignmentId"
helpMessage="Choose options" name="promotionAssignment"
multiple="true">
<c:forEach var="client" items="${clientList}">
<aui:option value="${client.key}">${client.value }</aui:option>
</c:forEach>
<aui:validator name="required"
errorMessage="Please Select At least One Client " />
</aui:select>
<aui:button type="submit" name="submit" value="submit" />
答案 0 :(得分:1)
仅将<aui:validator>
用作<aui:input>
标签的主体。对于其他标签,还有其他方法。
如果您只需要下拉列表的必填字段验证,建议您在required="true"
标签中使用<aui:select>
属性。这样做会显示默认的This field is required
消息。
如果您需要自定义错误消息,则必须使用<aui:script>
进行表单验证:
<aui:script use="aui-form-validator">
new A.FormValidator({
boundingBox: $("<portlet:namespace />myForm"),
rules: {
<portlet:namespace />promotionAssignment: {
required: true
}
},
fieldStrings: {
<portlet:namespace />promotionAssignment: {
required: 'Please select at least one client'
}
}
});
</aui:script>
以下是有关liferay验证的一些参考: https://community.liferay.com/forums/-/message_boards/message/17517133 http://www.liferaysavvy.com/2014/01/form-validation-in-liferay.html