如何在Liferay表单中验证<aui:select>?</aui:select>

时间:2013-12-10 14:24:06

标签: java validation liferay portlet alloy-ui

在View.jsp中我使用了创建了一个表单。它上面有一些输入和3个选择框,实际上我想验证所有这些输入。对于我使用的输入,但我不知道如何验证我的

其实我想验证这三个:

  1. <aui:select id="birthday_day" name="birthday_day">
  2. <aui:select id="birthday_month" name="birthday_month">
  3. <aui:select id="birthday_year" name="birthday_year">
  4. 这是我的view.jsp

            <portlet:actionURL var="myUrl">
        </portlet:actionURL>
    <aui:form enctype="multipart/form-data" action="<%= myUrl %>" method="POST" name="fm">
     <table border="0" bgcolor=#ccFDDEE>
            <tr>
                <td colspan="2" align="center"><b>Recruiment Form</b></td>
            </tr>
            <tr>
                <td colspan="2" align="center"></td>
            </tr>
            <tr>
                <td><b>First Name:<span>*</span></b></td>
                <td>
                    <aui:input name="fname" type="text">
                        <aui:validator name="required"/>
                    </aui:input>
                </td>
            </tr>
    
            <tr>
                <td><b>Last Name:<span>*</span></b></td>
                <td>
                    <aui:input name="lname" type="text">
                        <aui:validator name="required"/>
                    </aui:input>
                </td>
            </tr>
            <tr>
                <td><b>Father Name:<span>*</span></b></td>
                <td>
                    <aui:input name="father_name" type="text">
                        <aui:validator name="required"/>
                    </aui:input>
                </td>
            </tr>
            <tr>
                <td><b>Birth Date:<span>*</span></b></td>
                <td>
                    <aui:select id="birthday_day" name="<portlet:namespace/>birthday_day">
                        <aui:option value="0">روز</aui:option>
                        <%
                            for(int i=1;i<=31;i++) {
                        %>
                        <aui:option value="<%=i%>"><%=i%></aui:option>
                        <%
                            }
                        %>
                    </aui:select>
                    /
                    <aui:select id="birthday_month" name="birthday_month">
                        <aui:option value="0">ماه</aui:option>
                        <%
                            String[] monthBirthDay = {"فروردین","اردیبهشت","خرداد","تیر","مرداد","شهریور","مهر","آبان","آذر","دی","بهمن","اسفند"};
                            for(int j=0;j<monthBirthDay.length;j++) {
                        %>
                        <aui:option value="<%=j+1%>"><%=monthBirthDay[j]%></aui:option>
                        <%
                            }
                        %>
                    </aui:select>
                    /
                    <aui:select id="birthday_year" name="birthday_year">
                        <aui:option value="0">سال</aui:option>
                        <%
                            String[] yearBirthDay = {"1370","1369","1368","1367","1366","1365","1364"};
                            for(int j=0;j<yearBirthDay.length;j++) {
                        %>
                        <aui:option value="<%=yearBirthDay[j]%>"><%=yearBirthDay[j]%></aui:option>
                        <%
                            }
                        %>
                    </aui:select>
                </td>
            </tr>
      </table>
    </aui:form>
    

    我该如何解决这个问题?????? 请指导我。

2 个答案:

答案 0 :(得分:1)

只需为aui:select标记

指定一个id
<aui:select inlineField="true" label="xxx" name="xxx" id="xxxId">

然后你可以用这个(javascript + AUI)获得值

var selectedVal = A.one('#<portlet:namespace/>xxxId').val();

使用所选值,您可以执行任何类型的验证。

答案 1 :(得分:1)

<aui:select showEmptyOption="true" name="select hospital name" required="true">

</aui:select>

这可能会对你有所帮助。