Show which fields are required.

pull/7/head
Ferry Boender 9 years ago
parent 75a767f362
commit 847c42d644
  1. 11
      src/formrender.py
  2. 4
      src/webapp.py

@ -1,3 +1,5 @@
# -*- coding: utf8 -*-
"""
FormRender takes care of the rendering of forms to HTML.
"""
@ -22,6 +24,8 @@ HTML_FIELD_CHECKBOX = u'''
</li>
'''
HTML_REQUIRED = u'''{} <abbr title="This field is required" class="required">•</span>'''
class FormRender(object):
"""
@ -96,7 +100,12 @@ class FormRender(object):
params = self.cast_params(kwargs)
method_name = 'r_field_{0}'.format(field_type)
method = getattr(self, method_name, None)
return method(**params)
field = method(**params)
if 'required' in kwargs and kwargs['required'] is True:
return HTML_REQUIRED.format(field)
else:
return field
def r_field_string(self, name, value, minlen=None, maxlen=None, size=50,
required=False, classes=None, style=""):

@ -56,6 +56,7 @@ HTML_HEADER = u'''<html>
div.form p.form-field-input {{ margin-top: 0px; }}
div.form li.checkbox p.form-field-input {{ float: left;
margin-right: 8px; }}
div.form li.required abbr {{ color: #FF0000; }}
select,
textarea,
input[type=text],
@ -369,6 +370,9 @@ class ScriptFormWebApp(WebAppHandler):
if field.get('hidden', None):
params['classes'].append('hidden')
if field.get('required', None):
params['classes'].append('required')
params["style"] = field.get("style", "")
# Get field-specific parameters

Loading…
Cancel
Save