Enforce min and max dates on "date" fields in HTML5 capable browsers.

pull/7/head
Ferry Boender 10 years ago
parent 4771d60448
commit b8f19a1bba
  1. 10
      src/formrender.py
  2. 4
      src/webapp.py

@ -42,7 +42,7 @@ class FormRender(object):
u'max="{maxval}" step="any" name="{name}" ' u'max="{maxval}" step="any" name="{name}" '
u'value="{value}" class="{classes}" style="{style}" />', u'value="{value}" class="{classes}" style="{style}" />',
"date": u'<input {required} type="date" name="{name}" value="{value}" ' "date": u'<input {required} type="date" name="{name}" value="{value}" '
u'class="{classes}" style="{style}" />', u'min="{min}" max="{max}" class="{classes}" style="{style}" />',
"file": u'<input {required} type="file" name="{name}" ' "file": u'<input {required} type="file" name="{name}" '
u'class="{classes}" style="{style}" />', u'class="{classes}" style="{style}" />',
"password": u'<input {required} type="password" minlength="{minlen}" ' "password": u'<input {required} type="password" minlength="{minlen}" '
@ -143,16 +143,16 @@ class FormRender(object):
return tpl.format(name=name, value=value, minval=minval, maxval=maxval, return tpl.format(name=name, value=value, minval=minval, maxval=maxval,
required=required, classes=classes, style=style) required=required, classes=classes, style=style)
def r_field_date(self, name, value, required=False, classes=None, def r_field_date(self, name, value, min='', max='', required=False,
style=""): classes=None, style=""):
""" """
Render a date field to HTML. Render a date field to HTML.
""" """
if classes is None: if classes is None:
classes = [] classes = []
tpl = self.field_tpl['date'] tpl = self.field_tpl['date']
return tpl.format(name=name, value=value, required=required, return tpl.format(name=name, value=value, min=min, max=max,
classes=classes, style=style) required=required, classes=classes, style=style)
def r_field_file(self, name, required=False, classes=None, style=""): def r_field_file(self, name, required=False, classes=None, style=""):
""" """

@ -391,6 +391,10 @@ class ScriptFormWebApp(WebAppHandler):
params['minval'] = field.get("min", '') params['minval'] = field.get("min", '')
params['maxval'] = field.get("max", '') params['maxval'] = field.get("max", '')
if field['type'] in ('date'):
params['min'] = field.get('min', '')
params['max'] = field.get('max', '')
if field['type'] == 'text': if field['type'] == 'text':
params['rows'] = field.get("rows", '') params['rows'] = field.get("rows", '')
params['cols'] = field.get("cols", '') params['cols'] = field.get("cols", '')

Loading…
Cancel
Save