hi....

I am using date module. I got a requirement that the user should not enter the previous dates. I mean the date popup should show only present and future dates only. The granularity should be month. Here the widget type is "Date popup Calender"

can any body suggest how to do this......

Thanks in Advance.......

Comments

nags338228’s picture

can any body please suggest????
i googled but i didnt get.. pls help me..

nags338228’s picture

hurray I got the script.................

I think this snippet may help some body
place this code in head

<script>
	$(function() {
		var dates = $( "#textbox1id , #textbox2id" ).datepicker({
			defaultDate: "+1w",
			changeMonth: true,
			numberOfMonths: 1,
			minDate : 0,
			maxDate : "+3Y",
			onSelect: function( selectedDate ) {
				var option = this.id == "textbox1id" ? "minDate" : "maxDate",
					instance = $( this ).data( "datepicker" );
					date = $.datepicker.parseDate(
						instance.settings.dateFormat ||
						$.datepicker._defaults.dateFormat,
						selectedDate, instance.settings );
				dates.not( this ).datepicker( "option", option, date );
			}
		});
	});
</script>
qwerty1988’s picture

where to place this particular code
not clear about the head you specified

please do let know thanks in advance

nags338228’s picture

put that code in theme tag in page.tpl file, or if u r having any particular .tpl file., place.it.

umar.adil’s picture

did not work for me

I used as

drupal_add_js("
(function ($) {
$(document).ready(function() {
$('#edit-attendance-date-datepicker-popup-0' ).datepicker({ minDate: -10, maxDate: '+1M +10D' });
});
})(jQuery);
", 'inline');

$form['attendance_date'] = array(
'#type' => 'date_popup',
'#title' => t('Attendance date'),
'#description' => t('Please select the date of attendance'),
'#required' => TRUE,
'#date_format' => 'Y-m-d',
'#attributes' => array('autocomplete' =>'off','readonly' => 'readonly'),
'#default_value' => date('Y-m-d'),
);

umar.adil’s picture

drupal_add_js("
(function ($) {
$(document).ready(function() {
$('#edit-attendance-date-datepicker-popup-0' ).datepicker({ minDate: -10, maxDate: '+10M +10D' });
});
})(jQuery);
", 'inline');

$form['attendance_date'] = array(
'#type' => 'date_popup',
'#title' => t('Attendance date'),
'#description' => t('Please select the date of attendance'),
'#required' => TRUE,
'#date_format' => 'Y-m-d',
'#attributes' => array('autocomplete' =>'off','readonly' => 'readonly'),
'#default_value' => date('Y-m-d'),
);

Vincent Rommelaars’s picture

@umar.adil

Where did you put this code?
I cannot seem to get this to work...
Hope you can assist me on this.

I'm using a date picker in combination with 'uc_visit_time' on a order confirmation page.
Basic theme I use is 'Zeropoint'.

Thanks in advance

Fawad Ali’s picture

hello Sir i use the same code and place it into head portion using .info file and i am using the full calendar module .. i want that if some one select a date from popup_date its only select the present and furture dates please can you help me out

Houston Home Security’s picture

I read this post before. Maybe it'll help with setting only future dates? http://www.econcepts.co.uk/snippets/adding-date-validation-only-future-d...

Madis’s picture

There's a patch to get it backported for Drupal 6 as well, check the issue.

Simply put date_popup fields now accept custom options that are supported by jQuery UI datepicker. Example:

$form['date'] = array(
  '#type' => 'date_popup',
  '#title' => t('Date'),
  '#date_format' => 'd.m.Y',
  '#date_year_range' => '0:+3',
  '#datepicker_options' => array('minDate' => 0),
);

If you need to alter an existing form use hook_form_alter() and make sure you just add/change the necessary bits without overwriting everything:

$form['date']['#datepicker_options']['minDate'] = 0;
Diego Ruiz del Árbol’s picture

I am creating a website where users should manage with dates. It,s a website about tourism services, so, generally all picked dates have to belong to the future.

The thing is: I am not able to find where to apply what Madis is describing here. I have created a content type with a field of "Date" type, but I do not find any structure in my form that match '#type' => 'date_popup'. I find always the date_combo structure, but as I said no date_popup at all.

I am using latest Drupal version (7.23) and Date module version (7.x-2.8).

If I create the Date field myself through the API it works, but I am not able to modify the form that Drupal is generating.

Any help would be appreciated. Thanks in advance.

Diego

Diego Ruiz del Árbol’s picture

I answer myself. Obviously I was looking in the wrong place!
Instead of using a date_popup module hook, I was looking in the form through "hook_form_alter".

Finally I managed to modify the date_popup structure through hook_date_popup_process_alter (http://drupalcontrib.org/api/drupal/contributions!date!date.api.php/func...)

For example:

<?php
function custom_date_popup_process_alter(&$element, &$form_state, &$context) {
  $element['#datepicker_options'] = array(
  	'minDate' => "+2D",
  );
  $element['date'] = date_popup_process_date_part($element);
}
?>

Best, Diego

Anil Reddy Vallur’s picture

I have implemented the hook mentioned above with 'minDate' => "+1D" for showing only present and future dates.

tejprakash’s picture

Great..!!Thanks its worked for me.

phponwebsites’s picture

How to disable dates, if it is greater than current date in date module?
I've done myself as below:

/**
 * Implement hook_date_popup_process_alter().
 */
function phponwebsites_date_popup_process_alter(&$element, &$form_state, &$context) {
  $element['#datepicker_options'] = array(
      'maxDate' => "+0D",
  );
  $element['date'] = date_popup_process_date_part($element);
}
janmejaya’s picture

Very good solution. It worked for me.

rohit-rajput-sahab’s picture

Thanks its working.

Aaron23’s picture

Works Great..!!

Fawad Ali’s picture

i need the solution code if any one have the solution please help me out .... i have the same problem and test all the solutions from this page but fail not working for me

remyyyyy’s picture

Hello,
Which version of drupal ?