Skip to main content

Search and Top Navigation

#5446 closed feature (wontfix)

Opened March 29, 2010 08:36PM UTC

Closed July 16, 2014 02:50PM UTC

public function for querying a date's 'selectable' status

Reported by: andrewroazen Owned by:
Priority: major Milestone: none
Component: ui.datepicker Version: 1.8
Keywords: selectable validate Cc:
Blocked by: Blocking:
Description

The datepicker does not validate against manually entered dates that are blocked out through minDate/maxDate/beforeShowDay. Given the fact that applications are likely to generate datepickers programmatically, it is inconvenient for the developer to independently replicate the data structure and logic already inside ui.datepicker to retrieve a date's status for purposes such as validation.

With one public function, the datepicker object can return a boolean 'selectable' value for any passed date (or default to the current datepicker getDate if none is passed):

	/* Get the selectable status for a date in a jQuery selection.
	   @param  target  element - the target input field or division or span
	   @param  date    Date - the date being queried (defaults to the element's current date)
	   @return selectable - the status */
	_isSelectableDatepicker: function(target,date) {
		date = date || this._getDateDatepicker(target);
		var inst = this._getInst(target);
		if (inst && !inst.inline)
			var minDate = this._getMinMaxDate(inst, 'min', true);
			var maxDate = this._getMinMaxDate(inst, 'max');
			var beforeShowDay = this._get(inst, 'beforeShowDay');
			var daySettings = (beforeShowDay ? beforeShowDay.apply((inst.input ? inst.input[0] : null), [date]) : [true, '']);
			var selectable = !(!daySettings[0] || (minDate !=null && (date < minDate)) || (maxDate !=null && (date > maxDate)));
		return (inst ? selectable : null);
	},

and the argument parser is amended to include this function's name:

if (typeof options == 'string' && (options == 'isDisabled' || options == 'getDate' || options == 'widget' || options == 'isSelectable'))

A sample usage would be as follows:

	jQuery.validator.addMethod("dpicker", function(value, element) {
		selectable = $(element).datepicker("isSelectable");
		return (this.optional(element) || selectable);
	}, "Please choose a valid date");

To query a specific date in a datepicker, the syntax would be:

		selectable = $(element).datepicker("isSelectable",date);

where date is a date object rather than a parseable string (given the utility functions already baked into datepicker, this seems fair).

Attachments (1)
Change History (6)

Changed March 29, 2010 09:37PM UTC by andrewroazen comment:1

Also, for the 1.9 version the function would look as follows (if I understand the refactoring correctly):

/* Get the selectable status for a date in a jQuery selection.
   @param  date    Date - the date being queried (defaults to the element's current date)
   @return selectable - the status */
isSelectable: function(date) {
	date = date || this.retrieveDate();
	var minDate = this._get('minDate');
	var maxDate = this._get('maxDate');
	var onDate = this._get('onDate');
	onDate = ($.isFunction(onDate) ? onDate : null);
	var dateInfo = (!onDate ? {} : onDate.apply(this.element[0], [date]));
	var selectable = (dateInfo.selectable == null || dateInfo.selectable) &&
		(!minDate || date.getTime() >= minDate.getTime()) &&
		(!maxDate || date.getTime() <= maxDate.getTime());
	return selectable;
}

Changed February 27, 2012 03:30PM UTC by jzaefferer comment:2

status: newopen

We should make sure that the rewrite takes this into account.

Changed June 26, 2012 01:22AM UTC by scottgonzalez comment:3

type: enhancementfeature

Changed October 11, 2012 05:54PM UTC by scottgonzalez comment:4

#7279 is a duplicate of this ticket.

Changed July 14, 2014 04:52PM UTC by scottgonzalez comment:5

milestone: TBDnone

Changed July 16, 2014 02:50PM UTC by scottgonzalez comment:6

resolution: → wontfix
status: openclosed

This is actually not that inconvenient. You're just checking if the date is less than the min, greater than the max, or within your own custom list of dates. Given the lack of requests for this and the relatively simple implementation outside of the datepicker, and the fact that the datepicker would need to invoke a callback related to rendering when not actually rendering, this isn't something we're inclined to implement.