I want to make a field (as a behaviour if possible).
I want the user to be able to choose between dates from 01.01.2015 and today (current date).
A validator will do, but even better would be if the widget did not show dates before 2015 and after current date
How is this best done?
I think you can do this via Widget Manipulation like described in the Docs. Check the DateRange in Code and show/hide the widget.
self.widgets["getAvailability"].mode = z3c.form.interfaces.HIDDEN_MODE
I think Pick-A-Date is configurable to this effect, assuming you are using Mockup (Plone 5) or plone.app.widgets 1.x in Plone 4. You would add configuration for the date range in the 'date' dict of the form directive for the widget.
That said: I discovered that it is possible to set hardcoded dates TTW (in Dexterity Content types), like:
<field name="date" type="zope.schema.Date">
I assume it is not possible to use something like 'current date here', in case it is, please let me know...
Remember that mockup just wraps a pattern around PickADate. PickADate supports min/max being set programmatically in options. You can put this in your widget configuration:
In HTML, this would look like:
And you can pass options for mockup-based widgets in your schema using form directives, IIRC, looks like this:
# imports elided
"""Some content schema"""
min: [2015, 1, 1]
when = schema.Date()
where = schema.TextLine(default=u'Anywhere but here')
I had no idea that you could use directives like that, that is great.
I did not manage to get it to work, probably because I use it inside a tuple:
Anyway, for a tuple this works (I am putting the code here since it was not obvious for me, so maybe someone else could need it one day.... ):
return datetime.date.today() - datetime.timedelta(1)
""" Data field for tuple. min and max are not working inside the tuple
they need to be set in the tuple instead"""
""" Fields to construct the gabriel
graphs from JSON URLs"""
dates = schema.Tuple(
default = (theDefaultValue(),),
min=datetime.date(2015, 5, 12),
This will also 'pre-set' one date, so one does not need to add 'the first date'
How, exactly, are you using this / representing this on a form with a widget-per-date? If you are in fact using the mockup widgets, you ought to be able to set min/max.