Reputation:
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!
Upvotes: 2
Views: 6074
Reputation: 89
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.
Upvotes: 2
Reputation: 4543
A feature I hope to get to soon
http://bugs.dojotoolkit.org/ticket/4765
Upvotes: 1
Reputation: 12966
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"; }
Upvotes: 4