gpt4 book ai didi

java - aui validator 无法处理在 liferay 中提交的表单

转载 作者:行者123 更新时间:2023-12-02 09:52:01 27 4
gpt4 key购买 nike

我有一些带有某些字段的简单表单,我只想在客户端验证我的字段,所以我正在使用它并且它可以处理模糊事件

问题是当我提交表单时显示错误消息并且表单已提交

我正在尝试对表单提交进行验证,但如何才能知道哪个验证失败了

<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" />

最佳答案

仅使用<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

关于java - aui validator 无法处理在 liferay 中提交的表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56257325/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com