views:

1543

answers:

2

Quick question about the Dijit.Form.DateTextBox

http://docs.dojocampus.org/dijit/form/DateTextBox

This page contains the following: "also validates against developer-provided constraints like min, max, valid days of the week, etc."

I can't seem to find documentation allowing me to provide a constraint on the days of the week. For instance, i need to have a DateTextBox which only allows users to choose a date that occurs on a Sunday.

I'd appreciate any help with this. Thanks!

+3  A: 

I looked heavily into the source code for this, and I think the manual may be misleading you a bit - there's no way to do this using the object's constraints. The following quote from their user forums seems to back up my findings:

DateTextBox doesn't let you customize isDisabledDate at this time. It only lets you set min/max. You would probably have to patch or subclass DateTextBox to provide your own isDisabledDate implementation and check during validation.

You can see an example of such a subclass of DateTextBox at http://dojotoolkit.org/forum/dijit-dijit-0-9/dijit-support/datetextbox-mondays-only-selectable#comment-19508.

If that's too much work for you, DateTextBox DOES descend from dijit.form.ValidationTextBox, so we can use this widget's regExpGen to create a validator - it won't prevent us from selecting invalid dates, but it will cause dijit to mark the widget as invalid and give the user a 'The value entered is not valid'.

dijit.byId('toDate').regExpGen = function() { 
  if (dojo.date.locale.format(this.value, {datePattern: "E", selector: "date"}) == 6)
    return ".*";
  return "0";
}
TML
Is it possible to get access to the Calendar object which the DateTextBox contains. We have managed to disable weekends when we have access to this directly.
Andrew Harmel-Law
+1  A: 

A feature I hope to get to soon

http://bugs.dojotoolkit.org/ticket/4765

peller