Enforce minlen and maxlen on "text" fields in HTML5 capable browsers.

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

@ -49,8 +49,8 @@ class FormRender(object):
u'name="{name}" value="{value}" class="{classes}" ' u'name="{name}" value="{value}" class="{classes}" '
u'style="{style}" />', u'style="{style}" />',
"text": u'<textarea {required} name="{name}" rows="{rows}" ' "text": u'<textarea {required} name="{name}" rows="{rows}" '
u'cols="{cols}" style="{style}" ' u'cols="{cols}" minlength="{minlen}" maxlength="{maxlen}" '
u'class="{classes}">{value}</textarea>', u'style="{style}" class="{classes}">{value}</textarea>',
"radio_option": u'<input {checked} type="radio" name="{name}" ' "radio_option": u'<input {checked} type="radio" name="{name}" '
u'value="{value}" class="{classes} ' u'value="{value}" class="{classes} '
u'style="{style}"">{label}<br/>', u'style="{style}"">{label}<br/>',
@ -175,8 +175,8 @@ class FormRender(object):
return tpl.format(name=name, value=value, minlen=minlen, return tpl.format(name=name, value=value, minlen=minlen,
required=required, classes=classes, style=style) required=required, classes=classes, style=style)
def r_field_text(self, name, value, rows=4, cols=80, required=False, def r_field_text(self, name, value, rows=4, cols=80, minlen=None,
classes=None, style=""): maxlen=None, required=False, classes=None, style=""):
""" """
Render a text field to HTML. Render a text field to HTML.
""" """
@ -184,7 +184,8 @@ class FormRender(object):
classes = [] classes = []
tpl = self.field_tpl['text'] tpl = self.field_tpl['text']
return tpl.format(name=name, value=value, rows=rows, cols=cols, return tpl.format(name=name, value=value, rows=rows, cols=cols,
required=required, classes=classes, style=style) minlen=minlen, maxlen=maxlen, required=required,
classes=classes, style=style)
def r_field_radio(self, name, value, options, classes=None, style=""): def r_field_radio(self, name, value, options, classes=None, style=""):
""" """

@ -381,10 +381,10 @@ class ScriptFormWebApp(WebAppHandler):
if field['type'] == 'string': if field['type'] == 'string':
params['size'] = field.get('size', '') params['size'] = field.get('size', '')
if field['type'] in ('string', 'password'): if field['type'] in ('string', 'password', 'text'):
params['minlen'] = field.get('minlen', '') params['minlen'] = field.get('minlen', '')
if field['type'] in ('string'): if field['type'] in ('string', 'text'):
params['maxlen'] = field.get('maxlen', '') params['maxlen'] = field.get('maxlen', '')
if field['type'] in ('number', 'integer', 'float'): if field['type'] in ('number', 'integer', 'float'):

Loading…
Cancel
Save