Okay i just ask question about how to validate form with condition, now i have new problem, i have input text but it is readonly lets say call input text is address, and i have antoher input lets say call office. When i try input office,the text addres will sow up depends what i write on office. (I'm using ajax and mysql to get address), if that office didnt have data on mysql the address will not show up. Now my problem is on form validate, i need to check if the addres is empty i need show alert. How do i did that?? I try code like this
$('#form').validate({
errorElement: 'span',
errorClass: 'help-block',
rules: {
office : {
required : true
},
address: {
required: {
depends: function(element) {
if ($('#office').val() != '') {
return true;
} else {
return false;
}
}
}
}},
messages: {
Office : "Please insert name office",
address : "Seem office not quite right"
}
});
and here my html code
<form class="form-filter" id="form" role="form">
<div class="row">
<div class="col-md-4 col-sm-5">
<div class="form-group">
<label>
Office
</label>
<input type="text" placeholder="Insert name Office" class="form-control" id="Office" name="Office">
</div>
<div class="form-group">
<label>
Address
</label>
<input type="text" class="form-control" id="address" name="address" readonly>
</div>
<button type="submit">Check</button>
</from>
but when i try to submit it didnt work at all. If i try not filled my office it work prefectly. Or readonly cant be use on rules???
Upadte, is kinda buggy if i use readonly. So i try another solution i'm gonna try use even click button then.
Update again!! Okay i'm using button even click. and is work. so i just need check like this
$('#btnsave').click(function() {
if($("#form").valid()==true)
{
if($('#address').val()!="")
{
do something;
}
else
{
do alert;
}
}
});