Checkbox field type added.

pull/7/head
Ferry Boender 10 years ago
parent f69159f11f
commit 2dfa35a29b
  1. 11
      doc/MANUAL.md
  2. 5
      examples/megacorp_acc/job_restart_acc.sh
  3. 5
      examples/megacorp_acc/megacorp_acc.json
  4. 10
      src/scriptform.py

@ -16,6 +16,7 @@ This is the manual for version %%VERSION%%.
- [Float](#field_types_float)
- [Date](#field_types_date)
- [Radio](#field_types_radio)
- [Checkbox](#field_types_checkbox)
- [Select](#field_types_select)
- [Text](#field_types_text)
- [Password](#field_types_password)
@ -278,6 +279,16 @@ The `date` field type supports the following additional options:
### <a name="field_types_radio">Radio</a>
### <a name="field_types_checkbox">Checkbox</a>
The `checkbox` field type represents the user with a toggleble checkbox that
can be either 'on' or 'off'.
If the checkbox was checked, the value '`on`' is passed to the script.
Otherwise, '`off`' is passed. Unlike HTML forms, which send no value to the
server if the checkbox was not checked, Scriptform always sends either 'on' or
'off'.
### <a name="field_types_select">Select</a>
### <a name="field_types_text">Text</a>

@ -6,4 +6,9 @@ if [ "$passwd" != "123foobar" ]; then
fi
echo "RESTARTING"
if [ $no_db = "on" ]; then
echo "NOT RESTARTING DATABASE"
fi
ls -l /home/fboender

@ -70,6 +70,11 @@
"title": "Karl Karlsön gave you a password. What is it?",
"type": "password",
"required": true
},
{
"name": "no_db",
"title": "Do not restart the database",
"type": "checkbox"
}
]
},

@ -460,6 +460,13 @@ class FormDefinition:
"Invalid value for dropdown: {0}".format(value))
return value
def validate_checkbox(self, field_def, form_values):
value = form_values.get(field_def['name'], 'off')
if not value in ['on', 'off']:
raise ValidationError(
"Invalid value for checkbox: {0}".format(value))
return value
def validate_text(self, field_def, form_values):
value = form_values[field_def['name']]
minlen = field_def.get('minlen', None)
@ -662,6 +669,7 @@ class ScriptFormWebApp(WebAppHandler):
"password": u'<input {0} type="password" min="{1}" name="{2}" />',
"text": u'<textarea {0} name="{1}" rows="{2}" cols="{3}"></textarea>',
"select": u'<option value="{0}">{1}</option>',
"checkbox": u'<input {0} type="checkbox" name="{1}" />',
"radio": u'<input {0} type="radio" name="{1}" value="{2}">{3}<br/>',
}
@ -693,6 +701,8 @@ class ScriptFormWebApp(WebAppHandler):
radio_elems.append(tpl.format(checked, field['name'], option[0], option[1]))
checked = u'' # Check first radio option
input = u''.join(radio_elems)
elif field['type'] == 'checkbox':
input = tpl.format(required, field['name'])
elif field['type'] == 'text':
rows = field.get('rows', 5)
cols = field.get('cols', 80)

Loading…
Cancel
Save