Quick question about the 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!
Quick question about the Dijit.Form.DateTextBox
http://docs.dojocampus/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!
Share Improve this question asked May 18, 2009 at 22:00 ChaseChase3 Answers
Reset to default 4I 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/forum/dijit-dijit-0-9/dijit-support/datetextbox-mondays-only-selectable#ment-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"; }
As it happens, the isDisabledDate
function on the Calendar
object inside a DateTextBox
just calls rangeCheck
on the DateTextBox
itself. So, for your purposes, this will work:
dijit.byId('toDate').rangeCheck = function(date,constraints) {
var day=date.getDay();
return day===0;
}
You'd have to add the constraint logic back in if you ALSO wanted the min/max stuff, but this solves the problem as stated, and it's pretty short.
A feature I hope to get to soon
http://bugs.dojotoolkit/ticket/4765