File: jquery.datepicker.range.js

Recommend this page to a friend!
  Classes of Sandro Alves Peres   Date Picker Range   jquery.datepicker.range.js   Download  
File: jquery.datepicker.range.js
Role: Class source
Content type: text/plain
Description: DatePickerRange Plugin
Class: Date Picker Range
jQuery plugin to pick a range between two dates
Author: By
Last change: Verification of valid date, if the user wants to enter the date range
Date: 11 years ago
Size: 3,016 bytes
 

Contents

Class file image Download
/*------------------------------------------------------------------------ // This plugin is used to maintain consistency across a period of date // which uses the JQuery UI DatePicker // // 27/09/2013 - Sandro Alves Peres // http://www.zend.com/en/yellow-pages#show-ClientCandidateID=ZEND022656 // // Requires: // jquery.data.js //-----------------------------------------------------------------------*/ (function($){ $.datepickerRange = function( dateStart, dateEnd ) { dateStart = (typeof(dateStart) == 'object' ? dateStart : $('#' + dateStart)); dateEnd = (typeof(dateEnd) == 'object' ? dateEnd : $('#' + dateEnd)); dateStart.datepicker('option', 'onSelect', function() { if( $(this).val() == '' ) { dateEnd.datepicker('option', 'minDate', dateStart.datepicker('option', 'minDate')); } else { dateEnd.datepicker('option', 'minDate', dateStart.val()); } }); dateEnd.datepicker('option', 'onSelect', function() { if( $(this).val() == '' ) { dateStart.datepicker('option', 'maxDate', dateEnd.datepicker('option', 'maxDate')); } else { dateStart.datepicker('option', 'maxDate', dateEnd.val()); } }); dateStart.blur(function() { if( !$.isDate($(this).val()) ) { $(this).val(''); } else { if( $.toDays($(this).val()) > $.toDays(dateStart.datepicker('option', 'maxDate')) ) { $(this).val( dateStart.datepicker('option', 'maxDate') ); } else if( $.toDays($(this).val()) < $.toDays(dateStart.datepicker('option', 'minDate')) ) { $(this).val( dateStart.datepicker('option', 'minDate') ); } } }); dateEnd.blur(function() { if( !$.isDate($(this).val()) ) { $(this).val(''); } else { if( $.toDays($(this).val()) > $.toDays(dateEnd.datepicker('option', 'maxDate')) ) { $(this).val( dateEnd.datepicker('option', 'maxDate') ); } else if( $.toDays($(this).val()) < $.toDays(dateEnd.datepicker('option', 'minDate')) ) { $(this).val( dateEnd.datepicker('option', 'minDate') ); } } }); try { dateStart.datepicker('option', 'onSelect').call(); dateEnd.datepicker('option', 'onSelect').call(); } catch(e){} }; })(jQuery);