Field type 'checkbox': Added 'checked' option for field definition to indicate if the checkbox should be checked by default.

pull/7/head
Ferry Boender 9 years ago
parent f74e2b2d1e
commit 937a8b6706
  1. 11
      src/webapp.py

@ -297,11 +297,18 @@ class ScriptFormWebApp(RequestHandler):
params['options'] = field['options'] params['options'] = field['options']
if field['type'] == 'checkbox': if field['type'] == 'checkbox':
# Set default value from field definition
params['checked'] = False params['checked'] = False
if field['name'] in form_values and \ if 'checked' in field and field['checked']:
form_values[field['name']] == 'on':
params['checked'] = True params['checked'] = True
# Set value from submitted form if applicable
if field['name'] in form_values:
if form_values[field['name']] == 'on':
params['checked'] = True
else:
params['checked'] = False
h_input = fr_inst.r_field(field['type'], **params) h_input = fr_inst.r_field(field['type'], **params)
return fr_inst.r_form_line(field['type'], field['title'], return fr_inst.r_form_line(field['type'], field['title'],

Loading…
Cancel
Save