どこでも検索しましたが、解決策が見つからないようです。一度に 1 つのフィールドセットしか表示されない 3 つのフィールドセットを持つフォームを作成しようとしています。次のように見えるように、onkeyup検証が機能しています。
$("#contactInfoForm").validate({
debug:true,
onkeyup: false,
rules: {
firstName: {
required: true,
loginRegex: true,
minlength: 2
},
lastName: {
required: true,
minlength: 2
},
Email:{
required: true,
email: true
},
Email_confirm:{
required: true,
email: true,
equalTo: "#Email"
},
streetAddressBilling:{
required: true,
minlength: 3
},
billingCity:{
required: true,
digits: true,
minlength: 3
},
state:{
required: true
},
zip:{
required: true,
digits: true,
minlength: 3
},
phone:{
required: true,
digits: true,
minlength: 3,
phoneUS: true,
},
prefix:{
required: true,
digits: true,
minlength: 3
},
landline:{
required: true,
digits: true,
minlength: 4
}
},//end of rules
groups: {
DateofBirth: "phone prefix landline"
},
errorPlacement: function(error, element) {
if (element.attr("name") == "phone" || element.attr("name") == "prefix" || element.attr("name") == "landline")
error.insertAfter("#landline");
else
error.insertAfter(element);
},
messages:{
firstName: {
required: "Please enter first name",
lettersonly: "No numbers please",
loginRegex: "Login format not valid",
minlength: "Use at least 2 letters"
},
lastName: {
required: "Please enter last name",
lettersonly: "No numbers please",
minlength: "Use at least 2 letters"
},
Email: {
required: "Please enter your email",
email: "Please enter a valid email address"
},
Email_confirm: {
required: "Please enter your email",
email: "Please enter a valid email address",
equalTo: "Email addresses do not match"
},
streetAddressBilling:{
required: "Please enter your street address",
minlength: "Use at least 3 letters"
},
billingCity:{
required: "Please enter your city",
minlength: "Use at least 3 letters"
},
state:{
required: "Please select your state."
},
zip:{
required: "Please enter your zip code",
digits: "Please only use numbers",
minlength: "Use at least 5 letters"
},
phone:{
required: "Please enter your phone number",
digits: "Please only use numbers",
minlength: "Use 3 numbers"
},
prefix:{
required: "Please enter your phone number",
digits: "Please only use numbers",
minlength: "Use 3 numbers"
},
landline:{
required: "Please enter your phone number",
digits: "Please only use numbers",
minlength: "Use 4 numbers"
}
}//end of messages
});//end of contact info form validation rules
次にやろうとしているのは、各フィールドセットの最後に続行ボタンを配置することです。ボタンはそのフィールドセットのフォームをチェックし、検証された場合は次のフィールドセットを開きます。以下は、フィールドセットの HTML です。
<form onsubmit="return submitForm(this)" method="post" id="contactInfoForm" name="contactInfoForm" action="#">
<fieldset>
<legend class="accessible-text">Address</legend>
<ol>
<li class="fullInput">
<label id="caption_address1" for="address1">
Address
</label>
<input type="text" autocomplete="off" aria-required="true" placeholder="Street Address" class="fullInput" maxlength="30" id="address1" name="address1">
</li>
<li class="no-label fullInput">
<label class="accessible-text" id="caption_address2" for="address2">
Billing Address Line 2
</label>
<input type="text" maxlength="40" autocomplete="off" aria-required="false" placeholder="Street Address Line 2(Optional)" class="fullInput" id="address2" name="address2">
</li>
<li class="no-label">
<label class="accessible-text" id="caption_city" for="city">
City
</label>
<input type="text" aria-required="true" placeholder="City" maxlength="30" id="city" name="city">
</li>
<li class="no-label">
<label class="accessible-text" id="caption_state" for="state">
State
</label>
<select aria-required="true" class="required" name="state" id="state">
<option value="">State</option>
</select>
</li>
<li class="no-label">
<label class="accessible-text" id="caption_zipCode" for="zipCode">
ZIP
</label>
<input type="text" autocomplete="off" aria-required="true" placeholder="20151" name="zipCode" id="zipCode" maxlength="5">
</li>
<li>
<label class="fullInput" id="caption_phone" for="phone">
Main Contact Number <a href="">Why we need this</a><br>
<span class="accessible-text">Please enter your area code</span>
</label>
<input type="text" autocomplete="off" aria-required="true" placeholder="703" name="phone" id="phone" maxlength="3">
<label class="accessible-text" id="caption_prefix" for="prefix">
Enter the next 3 numbers
</label>
<input type="text" autocomplete="off" aria-required="true" placeholder="555" name="prefix" id="prefix" maxlength="3">
<label class="accessible-text" id="caption_landline" for="landline">
Enter the last 4 numbers
</label>
<input type="text" autocomplete="off" aria-required="true" placeholder="5555" name="landline" id="landline" maxlength="4">
</li>
</ol>
</fieldset>
</form>
ボタンの JS は次のとおりです。フェードには jquery ui を使用しています。
$("#button").on("click", function(event){
if($('#contactInfoForm').validate({
rules: {
firstName: {
required: true,
loginRegex: true,
minlength: 2
},
lastName: {
required: true,
minlength: 2
},
Email:{
required: true,
email: true
},
Email_confirm:{
required: true,
email: true,
equalTo: "#Email"
},
streetAddressBilling:{
required: true,
minlength: 3
},
billingCity:{
required: true,
digits: true,
minlength: 3
},
state:{
required: true
},
zip:{
required: true,
digits: true,
minlength: 3
},
phone:{
required: true,
digits: true,
minlength: 3,
phoneUS: true,
},
prefix:{
required: true,
digits: true,
minlength: 3
},
landline:{
required: true,
digits: true,
minlength: 4
}
},//end of rules
}))
{ //checks if it's valid
if($(this).valid()) {
$('#about_you_ver2').toggleClass("mod");
$('#nameFieldsetEdit').toggleClass("hide");
$('#name').fadeOut('xslow', function(){
//$(this).effect("highlight", {}, 2000);
}),
$('#billing_address').fadeIn('xslow', function(){
//$(this).effect("highlight", {}, 2000);
}),
$('#billing_container p').fadeIn('xslow', function(){
//$(this).effect("highlight", {}, 2000);
})
}//end of valid direction
}
else{
alert("I'm not valid");
}
});//end of onclick for button
情報を入力せずにボタンをクリックすると、フォームが検証に合格した時点で立ち往生しています。この問題を解決するにはどうすればよいですか?