Here is my scenario i have 3 accordion layout. Each accordion contain 1 form. Like that
<div id="collapseOne">
@using(Html.BeginForm("","",FormMethod.Post,new{id="formOne"}))
{
@Html.TextBoxFor(m=>m.Name)
@Html.ValidationMessageFor(m=>m.Name)
@Html.TextBoxFor(m=>m.City)
@Html.ValidationMessageFor(m=>m.City)
<input type="button" value="Next" id="btnOne" />
}
</div>
<div id="collapseTwo">
@using(Html.BeginForm("","",FormMethod.Post,new{id="formTwo"}))
{
@Html.TextBoxFor(m=>m.Age)
@Html.ValidationMessageFor(m=>m.Age)
@Html.TextBoxFor(m=>m.Address)
@Html.ValidationMessageFor(m=>m.Address)
<input type="button" value="Next" id="btnTwo" />
}
</div>
<div id="collapseThree">
@using(Html.BeginForm("MyAction","MyController",FormMethod.Post,new{id="formThree"}))
{
@Html.TextBoxFor(m=>m.Email)
@Html.ValidationMessageFor(m=>m.Email)
@Html.TextBoxFor(m=>m.City)
@Html.ValidationMessageFor(m=>m.Email)
<input type="submit" value="Finish" id="btnThree" />
}
</div>
Now validation checks doing well when i press Next Next in above accordions. But when someone comes directly to 3rd accordion and try to press finish then it validate only 3rd form. Here is my jquery
function PageEvents(){
$("#btnThree").click(function(event){
event.preventDefault();
if($("#formOne").valid()==false){
// Open first Accordion
}
else if($("#formTwo").valid()==false){
//Open second Accodion
}
else{
if($("#formThree").valid()){
$("#formThree").submit();
}
}
});
$("#btnOne").click(function (event) {
event.preventDefault();
if ($("#formOne").valid()) {
//trigger accordion two
$("collapseTwo").trigger("click");
}
});
$("#btnTwo").click(function (event) {
event.preventDefault();
if ($("#formTwo").valid()) {
//trigger accordion two
$("collapseThree").trigger("click");
}
});
If you want more description i will provide. Please guide me how to validate those forms which are not opened yet and user come directly in 3rd accordion and press finish button...
Thanks