jeudi 16 avril 2015

I want to use MVC form with validation

I have a html form and there is inputs when I changed radiobuttons. These radiobuttons have validations for empty case. For example I checked invoiceTypePerson and fill its input and then click submit button but form doesn't submit because of other radiobutton's input is empty. I want to submit them independent with each other. How can I do it? There are my codes below.



<div class="inputs">
@Html.RadioButtonFor(model => model.InvoiceType, InvoiceType.Person, new { id = "invoiceTypePerson" })
<label for="invoiceTypePerson" class="companyType">@T("RadioButton1")</label>
@Html.RadioButtonFor(model => model.InvoiceType, InvoiceType.Company, new { id = "invoiceTypeCompany" })
<label for="invoiceTypeCompany" class="companyType">@T("RadioButton2")</label>
</div>

<div class="inputs sirket">
@Html.TextBoxFor(model => model.TaxOffice, new { @class = "text-box single-line", required = "required" })
@Html.RequiredHint()
<span class="taxD"></span>
</div>

<div class="inputs sahis">
@Html.TextBoxFor(model => model.TcNumber, new { @class = "text-box single-line", required = "required" })
@Html.RequiredHint()
<span class="tc"></span>
</div>

<button class="add-address-button"></button>

if($("input[id='invoiceTypePerson']").is(":checked")){
$('.add-address-button').click(function(){
var tc = $('input[id*="Address_TcNumber"]').attr('value');
if (!tc) {
$("span.tc").html('TC is required');
return false;
}
else if(tc){
$("span.tc").html('');
}

var taxoffice = $('input[id*="Address_TaxOffice"]').attr('value');
if (!taxoffice) {
$("span.taxD").html('Taxoffice is required');
return false;
}
else if(tc){
$("span.taxD").html('');
}
});
}

Aucun commentaire:

Enregistrer un commentaire