0

私は助言が必要です!私はasp.net mvc razorページを持っています。私は、銀行口座の詳細やアドレス、最後の4 ssn、国、州などの銀行の詳細を確認するために必要なその他の情報を提出するための大きなフォームを持っています。 3つのdiv( 'billingContainer'、 'addressContainer'、 'accountContainer')でそれぞれのdivに関連フィールドが含まれ、各コンテナの下部に 'next'と 'back'ボタンがあります。次にjavascript/jqueryで、これらの特定のフィールドが各コンテナで有効であることを確認します。たとえば、アドレスフィールドが有効であれば、「次へ」ボタンを有効にして 'accountContainer'を表示/表示し、それらのフィールドのすべてがチェックされ、有効であれば送信することができます。したがって、ユーザーには、各ページのフィールドがすべて有効な場合にのみトラバースされる2-3ページがあるように見えます。これは最善の方法ですか、それぞれのコンテナごとにフォームを作成し、それぞれのフォームで完全な投稿を行い、途中でビューモデルにデータを保存する必要がありますか?asp.net mvc razorページのjqueryで特定のフォームフィールドを検証する

Quetion - 「addressContainer」という1つのコンテナ内のすべてのフィールドの検証を確認するには、次のボタンを有効にして、 'accountContainer'フォームの次の部分を表示できますか?その後、ユーザーがあるフィールドからテキストを削除して無効にすると、次のボタンを無効にして次のコンテナに移動できなくなります。ここで

は、各セクションは、私が表示され、

私は検証のためにチェックする方法

$(".showAddressContainerBtn").off('click').on('click', function() { 
 
    $("#billingContainer").hide(); 
 
    $("#addressContainer").show(); 
 
    $("#Country1").prop('disabled', true); 
 

 

 
    $(".showBillingContainerBtn").off('click').on('click', function() { 
 
    $("#billingContainer").show(); 
 
    $("#addressContainer").hide(); 
 
    }); 
 

 
    $(".showAccountContainerBtn").off('click').on('click', function() { 
 
    $("#addressContainer").hide(); 
 
    $("#accountContainer").show(); 
 

 
    $(".showAddressContainerFromAccountBtn").off('click').on('click', function() { 
 
     $("#addressContainer").show(); 
 
     $("#accountContainer").hide(); 
 

 

 
    }); 
 
    }); 
 
});
<form id="bankForm"> 
 
    <div id="billingContainer"> 
 
    <div class="row"> 
 
     <h2>Billing Country</h2> 
 
    </div> 
 
    <div class="row"> 
 
     @Html.DropDownListFor(m => m.SelectedCountryId, new SelectList(Model.CountryList, "Value", "Text"), new { @id = "Country", @class = "btn-group-lg countryList form-control selectpicker" }) 
 
    </div> 
 
    <div class="row"> 
 
     <h2>Payout methods in United States</h2> 
 
    </div> 
 
    <div class="row"> 
 
     <div class="col-sm-1"> 
 
     @Html.RadioButtonFor(m => m.TransferType, "bankaccount", new { id = "BankAccount", data_label = "" }) 
 
     </div> 
 
     <div class="col-sm-11"> 
 
     <div>Bank transfer in USD ($)</div> 
 
     <div>Get paid in 5-7 business days</div> 
 
     </div> 
 
    </div> 
 

 
    <div class="row"> 
 
     <hr /> 
 
    </div> 
 

 
    <div class="row"> 
 

 
     <div class="col-sm-12"> 
 
     <a class="btn btn-lg btn-link" href="/User/Payout" style="border: 1px solid #286090"><i class="fa fa-long-arrow-left" aria-hidden="true"></i> back</a> 
 
     <button class="btn btn-lg btn-primary pull-right showAddressContainerBtn">Next <i class="fa fa-long-arrow-right" aria-hidden="true"></i></button> 
 
     </div> 
 

 
    </div> 
 
    </div> 
 
    <div id="addressContainer" style="display: none"> 
 
    <div class="row"> 
 
     <h3>What's the address for this payout method?</h3> 
 
    </div> 
 

 
    <div class="row"> 
 
     <div class="form-group"> 
 
     <label for="AddressLine1">Street address</label> @Html.TextBoxFor(m => m.StreetAddressLine1, new { @id = "AddressLine1", @class = "form-control input-lg", placeholder = "e.g. 123 Main St." }) @Html.ValidationMessageFor(m => m.StreetAddressLine1, 
 
     "", new { @class = "text-danger" }) 
 
     </div> 
 
    </div> 
 

 
    <div class="row"> 
 
     <div class="form-group"> 
 
     <label for="AddressLine2">Apt, suite, bldg. (optional)</label> @Html.TextBoxFor(m => m.StreetAddressLine2, new { @id = "AddressLine2", @class = "form-control input-lg", placeholder = "e.g. Apt #6" }) @Html.ValidationMessageFor(m => m.StreetAddressLine2, 
 
     "", new { @class = "text-danger" }) 
 
     </div> 
 
    </div> 
 

 

 
    <div class="row"> 
 
     <div class="col-sm-6" style="padding-left: 0px; padding-right: 5px;"> 
 
     <div class="form-group"> 
 
      <label for="City">City</label> @Html.TextBoxFor(m => m.City, new { @id = "City", @class = "form-control input-lg" }) @Html.ValidationMessageFor(m => m.City, "", new { @class = "text-danger" }) 
 
     </div> 
 
     </div> 
 
     <div class="col-sm-6" style="padding-left: 5px; padding-right: 0px;"> 
 
     <div class="form-group"> 
 
      <label for="State">State/Province</label> @Html.DropDownListFor(m => m.StateCode, new SelectList(Model.StateList, "Value", "Text"), "", new { @id = "State", @class = "btn-group-lg countryList form-control selectpicker" }) @Html.ValidationMessageFor(m 
 
      => m.StateCode, "", new { @class = "text-danger" }) 
 
     </div> 
 

 
     </div> 
 
    </div> 
 

 
    <div class="row"> 
 
     <div class="form-group"> 
 
     <label for="PostalCode">Zip code/Postal code</label> @Html.TextBoxFor(m => m.PostalCode, new { @id = "PostalCode", @class = "form-control input-lg", placeholder = "e.g. 94102" }) @Html.ValidationMessageFor(m => m.PostalCode, "", new { @class 
 
     = "text-danger" }) 
 
     </div> 
 
    </div> 
 

 
    <div class="row"> 
 
     @Html.DropDownListFor(m => m.SelectedCountryId, new SelectList(Model.CountryList, "Value", "Text"), new { @id = "Country1", @class = "btn-group-lg countryList form-control selectpicker" }) 
 
    </div> 
 

 
    <div class="row"> 
 
     <hr /> 
 
    </div> 
 

 
    <div class="row"> 
 

 
     <div class="col-sm-12"> 
 
     <a class="btn btn-lg btn-link showBillingContainerBtn" style="border: 1px solid #286090"><i class="fa fa-long-arrow-left" aria-hidden="true"></i> back</a> 
 
     <button class="btn btn-lg btn-primary pull-right showAccountContainerBtn">Next <i class="fa fa-long-arrow-right" aria-hidden="true"></i></button> 
 
     </div> 
 

 
    </div> 
 

 
    </div> 
 
    <div id="accountContainer" style="display: none;"> 
 

 
    <div class="row"> 
 
     <h2>Add bank account info</h2> 
 
    </div> 
 

 
    <div class="row"> 
 
     <div class="form-group"> 
 
     <label for="LastFour">Last 4 SSN</label> @Html.TextBoxFor(m => m.LastFour, new { @id = "LastFour", @class = "form-control input-lg", placeholder = "e.g. 4530" }) @Html.ValidationMessageFor(m => m.LastFour, "", new { @class = "text-danger" }) 
 
     </div> 
 
    </div> 
 

 
    <div class="row"> 
 
     <div class="form-group"> 
 
     <label for="AccountName">Account holder name</label> @Html.TextBoxFor(m => m.AccountName, new { @id = "AccountName", @class = "form-control input-lg", placeholder = "e.g. First Last" }) @Html.ValidationMessageFor(m => m.AccountName, "", new { 
 
     @class = "text-danger" }) 
 
     </div> 
 
    </div> 
 

 
    <div class="row"> 
 
     <div class="form-group"> 
 
     <label for="Routing">Routing number</label> @Html.TextBoxFor(m => m.Routing, new { @id = "Routing", @class = "form-control input-lg", placeholder = "e.g. 123456789" }) @Html.ValidationMessageFor(m => m.Routing, "", new { @class = "text-danger" 
 
     }) 
 
     </div> 
 
    </div> 
 

 
    <div class="row"> 
 
     <div class="form-group"> 
 
     <label for="Account">Account number</label> @Html.TextBoxFor(m => m.Account, new { @id = "Account", @class = "form-control input-lg", placeholder = "e.g. 1234567890" }) @Html.ValidationMessageFor(m => m.Account, "", new { @class = "text-danger" 
 
     }) 
 
     </div> 
 
    </div> 
 

 
    <div class="row"> 
 
     <div class="form-group"> 
 
     <label for="ConfirmAccount">Confirm account number</label> @Html.TextBoxFor(m => m.ConfirmAccount, new { @id = "ConfirmAccount", @class = "form-control input-lg", placeholder = "e.g. 1234567890" }) @Html.ValidationMessageFor(m => m.ConfirmAccount, 
 
     "", new { @class = "text-danger" }) 
 
     </div> 
 
    </div> 
 

 
    <div class="row"> 
 

 
     <div class="col-sm-12"> 
 
     <a class="btn btn-lg btn-link showAddressContainerFromAccountBtn" style="border: 1px solid #286090"><i class="fa fa-long-arrow-left" aria-hidden="true"></i> back</a> 
 
     <button class="btn btn-lg btn-primary pull-right addAccountBtn">Next <i class="fa fa-long-arrow-right" aria-hidden="true"></i></button> 
 
     </div> 
 

 
    </div> 
 

 
    </div> 
 
</form>

+1

コントロールのグループの検証については、[この回答](https://stackoverflow.com/questions/25643394/mvc-force-jquery-validation-on-group-of-elements/25645097#25645097)を参照してください。 –

答えて

0

を非表示になりますコンテナ名とその周りのdivを持って示し、かみそりのコードと私のhtmlです1つのコンテナ内のすべてのフィールド、たとえば 'addressContainer'は、次のボタンを有効にして、 'accountContainer'フォームの次の部分を表示できますか?

解決方法:すべてのフィールドを段階的にインライン検証し、ユーザーがすべてのフィールドを検証して、何らかのアクションを実行するか、サーバーにポストバックすることをお勧めします。詳細については、そのリンクを参照してください。Click here for inline validation plugin

also you can get some help from here

ユーザーが1つのフィールドからテキストを削除し、それを無効にした場合、彼/彼女が次のコンテナに移動することはできませんので、その後、私は次のボタンを無効にするでしょうか?

解決策:あなたのケースの全体的なソリューションがインライン検証となるため、もう一度onTextChange関数を使用することができます。

関連する問題