1. Put the function below in assets/js/jquery.validate.js
jQuery.validator.addMethod("greaterStart", function (value, element, params) {
//return this.optional(element) || new Date(value) > new Date($(params).val());
var check = false;
if(value >= $(params).val()){
check = true;
} else
check = false;
return this.optional(element) || check;
},'Tarikh Hingga perlu lebih besar atau sama dengan tarikh Dari');
2. Put the function below in assets/validation/pengaktifan.js
$(document).ready(function(){
$('#ulangan_kemaskini').validate(
{
rules: {
idAmbilan: {
minlength: 1,
number: true,
required: true
},
kodUjian: {
minlength: 1,
required: true
},
siri: {
minlength: 1,
number: true,
required: true
},
tarikhMulaUlang: {
maxlength: 100,
required: true
},
tarikhAkhirUlang: {
maxlength: 100,
required: true,
greaterStart: '#tarikhMulaUlang'
},
statusUjian: {
minlength: 1,
required: true
},
},
highlight: function(element) {
$(element).closest('.control-group').removeClass('success').addClass('error');
},
success: function(element) {
element
.text('OK!').addClass('valid')
.closest('.control-group').removeClass('error').addClass('success');
}
});
});
3. Create date picker fields for start & end date in views. Example : views/pengaktifanUlangan/ujian_ulangan.php
<!--<div class="row-fluid">
<div class="span12">
<div class="well">
Button to trigger modal
<a href="#myModal" role="button" class="btn" data-toggle="modal"><i class="icon icon-plus"></i>Tambah</a>
<a href="<?php echo site_url($this->controller.'/excel'); ?>" class="btn"><i class="icon icon-arrow-down"></i>Muat turun ke excel</a>
<a href="<?php echo site_url($this->controller.'/pdf'); ?>" class="btn"><i class="icon icon-print"></i>Muat turun ke PDF</a>
</div>
</div>
</div>-->
<div class="row-fluid">
<i><b>Sila klik pada rekod ujian untuk mengaktifkan ujian ulangan atau klik pada bilangan calon untuk melihat senarai calon :</b></i><br>
<i><b><font style=" color: #CC0000">Makluman : Pengemaskinian tarikh ulangan hanya boleh dilakukan pada siri ujian yang tarikh tutupnya sudah tamat.</font></b></i>
</div>
<div class="line"></div>
<div id="listUser"></div>
<div id="callback"></div>
<div id="myModalUpdate" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
<h3 id="myModalLabel">Kemaskini Ujian Ulangan</h3>
</div>
<div class="modal-body">
<?php echo tbs_horizontal_form_open('', array('id'=>'ulangan_kemaskini'));?>
<?php echo tbs_horizontal_input(array( //validation using jquery -> assets/validation/register.js
'name'=>'idAmbilan',
'id'=>'idAmbilan',
'value'=>set_value('idAmbilan', $ulangan['idAmbilan']),
'class'=>'input-small',
'maxlength'=>'2',
'readonly' => 'readonly',
), array(
'label'=>'ID Ambilan',
), true);?>
<?php echo tbs_horizontal_dropdown('kodUjian', $kodUjian_list, $ulangan['kodUjian'],
array('id'=>'kodUjian','class'=>'','disabled'=>'disabled',),
array('label'=>'Jenis Ujian','class'=>'',),
true);
?>
<?php echo tbs_horizontal_input(array( //validation using jquery -> assets/validation/register.js
'name'=>'siri',
'id'=>'siri',
'value'=>set_value('siri', $ulangan['siri']),
'class'=>'input-small',
'maxlength'=>'2',
'readonly' => 'readonly',
), array(
'label'=>'Siri',
), true);?>
<?php echo tbs_horizontal_input(array(
'name'=>'tarikhMulaUlang',
'id'=>'tarikhMulaUlang',
'data-date-format'=>'dd-mm-yyyy',
'value'=> set_value('tarikhMulaUlang', $ulangan['tarikhMulaUlang']),
'class'=>'input-large',
'maxlength'=>'50',
), array(
'label'=>'Dari',
), true); ?>
<?php echo tbs_horizontal_input(array(
'name'=>'tarikhAkhirUlang',
'id'=>'tarikhAkhirUlang',
'data-date-format'=>'dd-mm-yyyy',
'value'=> set_value('tarikhAkhirUlang', $ulangan['tarikhAkhirUlang']),
'class'=>'input-large',
'maxlength'=>'50',
), array(
'label'=>'Hingga',
), true); ?>
<?php echo tbs_horizontal_dropdown('statusUjian',$statusUjian, $ulangan['status'],
array('id'=>'statusUjian','class'=>'',),
array('label'=>'Status Ujian','class'=>'',),
true);
?><br>
<?php echo form_close();?>
</div>
<div class="modal-footer">
<button class="btn btn-orange" id="update">Kemaskini</button>
<button class="btn btn-orange" data-dismiss="modal" aria-hidden="true">Tutup</button>
</div>
</div>
<script src='<?php echo base_url('assets/validation/pengaktifan.js')?>'></script>
<script>
window.listUser = function(){
AjaxCall(base_url+'index.php/pengaktifanUlangan/listJson_ulangan', '', 'listUser', 'id', '', '');
};
$(document).ready(function(){
listUser();
$('#edit').live('click', function () {
var id = $(this).attr('attr');
var options = {
'id' : id
};
$.post(base_url+'index.php/pengaktifanUlangan/ulangan_papar', options, function(data) {
$.each(data, function(key, value){
$("#myModalUpdate .modal-body #"+key).val( value );
});
}, "json");
});
$('#update').live('click', function() {
var check_validate = $('#ulangan_kemaskini').valid();
if(check_validate == true){
var $var = ""; //php variable
$('#ulangan_kemaskini').find(':input').each(function(key, val){ //find all input in form and put in array
$var += val.name+"="+val.value+"&";
});
AjaxCall(base_url+'index.php/pengaktifanUlangan/ulangan_kemaskini', $var, '', '', 'listUser()', 'jAlert');
$('#myModalUpdate').modal('hide');
}
});
$('#myModal').on('hide', function(){
$("#myModal .modal-body input[type='text'], #myModal .modal-body select").val('');
$("#myModal .modal-body input[type='checkbox']").each(function(){
$(this).attr('checked',false);
$(this).closest('div').children('div').slideUp('fast').find('input').attr('disabled',true);
});
});
$('#tarikhMulaUlang').datepicker({
//format: 'dd-mm-yyyy',
autoclose: true,
startDate: '<?php echo date('d-m-Y') ?>'
}).on('hide', function(e){
$(this).valid();
});
$('#tarikhAkhirUlang').datepicker({
//format: 'dd-mm-yyyy',
autoclose: true,
startDate: '<?php echo date('d-m-Y') ?>'
}).on('hide', function(e){
$(this).valid();
});
});
</script>
Friday, 23 October 2015
CHECK VALIDITY BETWEEN START DATE & END DATE
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment