首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >aui验证器在救生艇的表单提交中不起作用

aui验证器在救生艇的表单提交中不起作用
EN

Stack Overflow用户
提问于 2019-05-22 20:55:42
回答 1查看 1.2K关注 0票数 0

我有一些字段的简单表单,我只是想在客户端验证我的字段,所以我使用它在模糊事件上工作

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

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

代码语言:javascript
运行
复制
<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" />

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-23 12:48:39

仅使用<aui:validator>作为<aui:input>标记的主体。对于除此之外的标签,还有其他方法。

如果您只需要对下拉列表进行必需的字段验证,我建议您使用<aui:select>选项卡中的required="true"属性。这样做将显示默认的This field is required消息。

如果您需要自定义错误消息,则必须使用<aui:script>进行表单验证:

代码语言:javascript
运行
复制
<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>

以下是有关救生索验证的一些参考资料:https://community.liferay.com/forums/-/message_boards/message/17517133 http://www.liferaysavvy.com/2014/01/form-validation-in-liferay.html

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56257325

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档