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

标签 java html liferay liferay-7 liferay-aui

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

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

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

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

相关文章:

java - Liferay - 调度程序未在给定时间触发

java - 如何在不重启应用程序服务器的情况下在 spring 中重新初始化 beans

java - 在 Gradle 中应用 Android 插件时找不到 org.gradle.api.artifacts.result.ResolvedModuleVersionResult

java - Hibernate 返回 com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException : Duplicate entry

java - Android AlertDialog 设置文本

html - 如何选择h4标题

html - 试图在表格上显示 div

javascript - 从数组值生成数组菜单

liferay portlet 中的 JavaScript

linux - 如何配置 Linux Ubuntu 可以处理的文件名长度?