現在、2つの.jspページといくつかのjQuery検証に関する検証の問題が発生しています。
要するに問題:私は私のページに選択要素のセットを持っています。空のフィールドはありません。ただし、フォームを送信する場合、フィールドは無効としてマークされます。jQueryコードはファイルsearchbox.jspにあり、実際のフォームはファイルsearchform.jspにあります。Searchformはsearchboxファイルに含まれるようになります。
検証コードスニペットは次のとおりです。
jQuery("#car-search").validate({
// onkeyup: false,
onfocusout: false,
focusInvalid: false,
focusCleanup: true,
rules : {
"pickupLocationName" : {
required : true,
fullLocation : true,
minlength : 3
},
"pickupDate" : {
required : true,
minlength : 1
},
"pickupTimeHours": {
required: true
},
"returnLocationName": {
required: true,
fullLocation : true,
minlength: 3
},
"returnDate" : {
required : true,
minlength : 1
},
"returnTimeHours": {
required: true
},
"driverFirstname": {
required: true,
minlength: 2
},
"driverLastname": {
required: true,
minlength: 2
},
"driverBirthdate": {
required: true,
minlength: 10,
maxlength: 10,
realDate: true
}
},
messages : {
"pickupLocationName" : "<spring:message code="car_search.pickup_location.required" />",
"returnLocationName" : "<spring:message code="car_search.return_location.required" />",
"pickupDate" : "<spring:message code="car_search.pickup_date.required" />",
"returnDate" : "<spring:message code="car_search.return_date.required" />",
"pickupTimeHours": "<spring:message code="car_search.pickup_time.required" />",
"returnTimeHours": "<spring:message code="car_search.return_time.required" />",
"driverFirstname": "<spring:message code="car_search.driver_firstname.required"/>",
"driverLastname": "<spring:message code="car_search.driver_lastname.required"/>",
"driverBirthdate": "<spring:message code="car_search.driver_birthdate.required"/>"
},
showErrors : function(errorMap, errorList) {
if (!validationMessageIsShown) {
jQuery(".invalidFormMessage #invalidFormItems").text("");
this.defaultShowErrors();
if(this.numberOfInvalids()>0){
jQuery(".invalidFormMessage").jqmShow();
}
validationMessageIsShown = true;
}
},
invalidHandler : function (form, validator) {
validationMessageIsShown = false;
},
submitHandler: function(form) {
showLoading();
form.submit();
},
errorPlacement : function(error, element) {
error.appendTo("#invalidFormItems");
}
});
そして、このスニペットは次の形式です。
<form:form commandName="carSearchForm" method="post" action="${actionUrl}" id="car-search" cssClass="searchForm">
<fieldset>
...
<div class="blueDottedBorder"></div>
</div>
<div class="usaStep step3">
<h4><spring:message code="car_search.driver_section"/> <span class="normal"><spring:message code="car_search.driver_section_info"/></span></h4>
<div class="clr">
<form:label path="driverFirstname" cssClass="big"><spring:message code="car_search.driver_firstname"/></form:label>
<c:choose>
<c:when test="${empty adultFirstNames}">
<form:input path="driverFirstname" id="driverFirstname"/>
</c:when>
<c:otherwise>
<form:select path="driverFirstname" id="driverFirstname" >
<form:options items="${adultFirstNames}" />
</form:select>
</c:otherwise>
</c:choose>
</div>
<div class="clr">
<form:label path="driverLastname" cssClass="big"><spring:message code="car_search.driver_lastname"/></form:label>
<c:choose>
<c:when test="${empty adultLastNames}">
<form:input path="driverLastname" id="driverLastname" />
</c:when>
<c:otherwise>
<form:select path="driverLastname" id="driverLastname" >
<form:options items="${adultLastNames}" />
</form:select>
</c:otherwise>
</c:choose>
</div>
<div class="clr">
<form:label path="driverBirthdate" cssClass="big"><spring:message code="car_search.driver_birthdate"/></form:label>
<c:choose>
<c:when test="${empty adultBirthdays}">
<form:input path="driverBirthdate" size="10" maxlength="10" cssClass="birthdate" id="driverBirthdate" />
</c:when>
<c:otherwise>
<form:select path="driverBirthdate" items="${adultBirthdays}" id="driverBirthdate" >
<form:options items="${adultBirthdays}" />
</form:select>
</c:otherwise>
</c:choose>
</div>
<div class="info-msg" style="padding-left: 30px; margin-top: 30px;" id="extraPointCost"><spring:message code="car_search.warning_surcharge" /> <a href="<url:car-rental_drop-off-cost />" target="_blank" class="more"><spring:message code="car_search.warning_surcharge.link_label" /></a></div>
</div>
<div style="margin-top: 30px;"><a href="<url:car-rental_conditions />" target="_blank" class="more"><spring:message code="car_search.rental_conditions.link_label" /></a></div>
</div>
<input type="submit" class="submit" value="<spring:message code="car_search.submit"/> »"/>
</fieldset>
</form:form>
フォームから無関係なフィールドを削除しました。この問題は、driverFirstname、driverLastname、およびdriveBirthdateフィールドにのみ適用されます。
値がない場合(つまり、挿入されたリストがオプションタグで空の場合)、すべてが正常に機能します。検証は、その時点で通常の入力フィールドにあるフィールドで正常に機能します。
この問題は、リストが空でない場合に発生するため、選択できるオプションが少なくとも1つまたは複数ある場合に発生します。フォームスニペットでわかるように、実際にオプションがある場合、入力フィールドは選択フィールドになります。その場合、フィールドが空でなく、値のサイズが2より大きい場合でも、フォームは検証に合格しません。
これは本当に私を困惑させます。私は選択したフィールドの既知の問題をグーグルで探していました、私はこのフォーラムでかなりの数の投稿を見ました、しかし提案された解決策のどれもうまくいかないでしょう(私は認めなければなりません、いくつかは本当に何に合わないように見えるので私はそれらすべてを試していませんが欲しいです)。
何かご意見は?
前もって感謝します。