I'm using the jQuery validation plugin, so far so good until I found a minor problem, but it has quite an impact to the UX. Note: other form validation is working well. Here's my scripts to initiate jQuery validation
$(document).ready(function() {
//jquery validation plugin
$('#user-register-form').validate({
rules: {
fullname: {
minlength: 3,
required: true
},
email:{
email:true
},
password: {
minlength: 8,
required: true
},
bornday:{
required:true
},
bornmonth:{
required:true
},
bornyear:{
required:true
}
},
highlight: function(element) {
$(element).parents('.form-group').addClass('has-error');
},
unhighlight: function(element) {
$(element).parents('.form-group').removeClass('has-error');
},
errorElement: 'span',
errorClass: 'validation-error-message help-block form-helper bold',
errorPlacement: function(error, element) {
if(element.parent('.input-group').length) {
error.insertAfter(element.parent());
} else {
error.insertAfter(element);
}
}
});
}); //end of document ready
<div class="form-group">
<label class="col-xs-12 col-sm-4 control-label" for="bornday">
Tanggal Lahir
<span class="text-red">*</span>
</label>
<div class="col-sm-8">
<div class="row">
<div class="col-md-3 col-sm-3 col-xs-4">
<select name="bornday" class="form-control input-w" required>
<option value="">Tanggal</option>
<?php for($i = 1; $i <= 31; $i++) {
$selected = $register_data['bornday'] == $i ? 'selected' : '';
$tgl = $i < 10 ? '0'.$i : $i; echo '<option value="'.$tgl. '" '.$selected. '>'.$i. '</option>';
} ?>
</select>
</div>
<div class="col-md-3 col-sm-3 col-xs-4">
<select name="bornmonth" class="form-control input-w" required>
<option value="">Bulan</option>
<?php foreach($month as $k => $v) {
$selected = $register_data['bornmonth'] == $k ? 'selected' : ''; echo '
<option value="'.$k.'" '.$selected.'>'.$v.'</option>';
} ?>
</select>
</div>
<div class="col-md-3 col-sm-3 col-xs-4">
<select name="bornyear" class="form-control input-w" required>
<option value="">Tahun</option>
<?php
$start_year = date('Y') - 75;
$end_year = date('Y') - 10;
for($y = $start_year; $y <= $end_year; $y++) {
$selected = $register_data['bornyear'] == $y ? 'selected' : '';
echo '<option value="'.$y. '" '.$selected. '>'.$y. '</option>';
} ?>
</select>
</div>
</div>
</div>
When I click submit other forms will be validated and changed to red border, including the error message, and then here is the problem:
for my birthdate form (with 3 <select> fields) when I click submit, the color doesn't immediately change to red.
but when i clicked anywhere else, the color started to change, but it highlights all of it (probably because it affects the whole .form-group)
NOTE: that problem only happen when i didn't fill the birthdate completely, but when i didn't select any of the date, the border color works well
Here is the link to the jsfiddle
https://jsfiddle.net/d7bhax8q/1/
if i need to add some more detail, please let me know, i really appreciate your help :)


