Javascript 为什么是AUI';文本字段';之前的s下拉列表需要验证;s验证

Javascript 为什么是AUI';文本字段';之前的s下拉列表需要验证;s验证,javascript,validation,liferay,liferay-6,liferay-aui,Javascript,Validation,Liferay,Liferay 6,Liferay Aui,我在表单liferay上使用了AUI taglib和一些文本字段和下拉列表。两者都需要验证。代码如下: <aui:form name="projectInformationForm" action="${projectInformation}" method="post"> <aui:fieldset label="company.details"> <aui:layout> <aui:column co

我在表单liferay上使用了AUI taglib和一些文本字段和下拉列表。两者都需要验证。代码如下:

<aui:form name="projectInformationForm" action="${projectInformation}" method="post">

    <aui:fieldset label="company.details">
        <aui:layout>
            <aui:column columnWidth="50">
                <aui:input type="text" name="nameOfTheProject"
                    label="name.of.the.project" inlineLabel="true">
                    <aui:validator name="required"></aui:validator>
                </aui:input>

                <aui:input type="text" name="investmentCost" label="investment.cost"
                    inlineLabel="true">
                    <aui:validator name="required"></aui:validator>
                    <aui:validator name="number"></aui:validator>
                </aui:input>

                <aui:select name="typeOfIndustry" label="type.of.industry"
                    inlineLabel="true" required="">
                    <aui:option label="selection.defult" value="" selected="true"></aui:option>                      
                </aui:select>

                <aui:input type="text" name="expectedDateOfStart" label="expected.date.of.start"
                    inlineLabel="true" cssClass="date-picker" >
                    <aui:validator name="required"></aui:validator>
                    <aui:validator name="date"></aui:validator>
                </aui:input>

                <aui:input type="text" name="expectedDateOfCommissioning"
                    label="expected.date.of.commissioning" inlineLabel="true"
                    cssClass="date-picker" >
                    <aui:validator name="required"></aui:validator>
                    <aui:validator name="date"></aui:validator>
                </aui:input>

            </aui:column>
        </aui:layout>
    </aui:fieldset>
    <aui:button-row>
        <aui:button type="button" value="back.text" first="true" onClick="location.href='${showGeneralInformation}'" />
        <aui:button type="submit" value="save.as.draft" onClick="saveNext(this)" />
        <aui:button type="cancel" value="cancel.text" />
        <aui:button type="submit" value="next.text" onClick="saveNext(this)" last="true" />
    </aui:button-row>
    <aui:script>
        function saveNext(button){
            var element = document.getElementById("<portlet:namespace/>buttonNameId");
            element.value = button.value;
        }
    </aui:script>
</aui:form>

功能保存下一步(按钮){
var元素=document.getElementById(“buttonNameId”);
element.value=button.value;
}
当我提交时,第一个选择字段的所需验证将运行,并在选择下拉值后显示错误消息,然后重新提交,然后再次显示文本字段验证消息

但我希望它显示所需的信息的顺序和形式

我做错了什么

谢谢
Sanjeet Jha

我认为最好的方法是使用
例如,对于必填字段,请使用以下代码片段:

<aui:validator name="custom" errorMessage="field.required">
    function (val, fieldNode, ruleValue) {
        if(val.length > 0) {
            return true;
        } else {
            return false;
        }
    }
</aui:validator>

函数(val、fieldNode、ruleValue){
如果(值长度>0){
返回true;
}否则{
返回false;
}
}

因此,您可以对每种自定义验证器类型使用此自定义验证器:minLength、maxlength、alpha(使用正则表达式),等等。

不幸的是,您无法在
中添加
,如果这样做,Liferay将抛出
NullPointerException
。@apcuk您说得对!尝试使用YUI验证程序捕获表单错误。