Date widget just for some dates

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

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.

import z3c.form.interfaces

    def updateWidgets(self):
        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 1.x in Plone 4. You would add configuration for the date range in the 'date' dict of the form directive for the widget.


Thanks everyone.

I could not find that mockup has options for this (?), but a (new) javascript works.

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

class IWhenWhere(model.Schema):
    """Some content schema"""

            'date': {
                min: [2015, 1, 1]
    when = schema.Date()

    where = schema.TextLine(default=u'Anywhere but here')


1 Like

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.timedelta(1)

def maxValue():

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"""
class IGabrielBehavior(form.Schema):
    """ Fields to construct the gabriel
    graphs from JSON URLs"""
    dates = schema.Tuple(
    	default = (theDefaultValue(),),
  , 5, 12),

This will also 'pre-set' one date, so one does not need to add 'the first date'

1 Like

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.