I want to make a field (as a behaviour if possible).
I want to use the date time widget (or something else, like a string field with a javascript if that is better).
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
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.
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:
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.... ):
def theDefaultValue():
return datetime.date.today() - datetime.timedelta(1)
def maxValue():
return datetime.date.today()
class IDate(schema.Date):
""" Data field for tuple. min and max are not working inside the tuple
they need to be set in the tuple instead"""
date=schema.Date(
title=_(u"Dato"),
defaultFactory=theDefaultValue,
)
class IGabrielBehavior(form.Schema):
""" Fields to construct the gabriel
graphs from JSON URLs"""
dates = schema.Tuple(
title=_(u"Datoer"),
required=True,
default = (theDefaultValue(),),
value_type=IDate(
title=_(u"Dato"),
min=datetime.date(2015, 5, 12),
max=datetime.date.today(),
defaultFactory=theDefaultValue,
)
)
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.