Allow 'today' for 'date' field values.

pull/7/head
Ferry Boender 5 years ago
parent cd64098a24
commit 8c640b33a6
  1. 25
      doc/MANUAL.md
  2. 9
      src/formrender.py

@ -836,13 +836,16 @@ enter a date. Depending on the browser's support for HTML5 forms, the input
field may have a pop-out calendar from which the user can select a date.
The date must be entered, and will be passed to the callback, in the form
YYYY-MM-DD.
`YYYY-MM-DD`.
The `date` field type supports the following additional options:
- **`min`**: The minimum allowed date (format: a string YYYY-MM-DD)
- **`max`**: The maximum allowed date (format: a string YYYY-MM-DD)
- **`default_value`**: The default value.
- **`min`**: The minimum allowed date (format: a string `YYYY-MM-DD`) or
"`today`" for today.
- **`max`**: The maximum allowed date (format: a string `YYYY-MM-DD`) or
"`today`" for today.
- **`default_value`**: The default value (format: a string `YYYY-MM-DD`) or
"`today`" for today.
For example:
@ -858,6 +861,20 @@ For example:
]
...
Must start today or in the future (Default value today):
...
"fields": [
{
"name": "startdate",
"title": "Start date",
"type": "date",
"min": "today",
"default_value": "today"
}
]
...
### <a name="field_types_radio">Radio</a>
The `radio` field type lets the user pick one option from a list of options.

@ -4,6 +4,9 @@
FormRender takes care of the rendering of forms to HTML.
"""
import datetime
HTML_FIELD = u'''
<li class="{classes}">
<p class="form-field-title">{title}</p>
@ -140,6 +143,12 @@ class FormRender(object):
Render a date field to HTML.
"""
tpl = self.field_tpl['date']
if value == "today":
value = datetime.datetime.now().strftime("%Y-%m-%d")
if minval == "today":
minval = datetime.datetime.now().strftime("%Y-%m-%d")
if maxval == "today":
maxval = datetime.datetime.now().strftime("%Y-%m-%d")
return tpl.format(name=name, value=value, minval=minval, maxval=maxval,
required=required, classes=classes, style=style)

Loading…
Cancel
Save