Implemented "default_value" form option.

pull/7/head
Ferry Boender 7 years ago
parent f93b742845
commit 2ea31d98ff
  1. 8
      doc/MANUAL.md
  2. 30
      examples/megacorp_acc/megacorp_acc.json
  3. 5
      src/formdefinition.py
  4. 1
      src/scriptform.py
  5. 3
      src/webapp.py

@ -756,6 +756,7 @@ The `string` field type supports the following additional options:
- **`minlen`**: The minimum allowed length for the field.
- **`maxlen`**: The maximum allowed length for the field.
- **`size`**: The size (in characters) of the input field.
- **`default_value`**: The default value.
For example:
@ -782,6 +783,7 @@ The `integer` field type supports the following additional options:
- **`min`**: The minimum allowed value for the field.
- **`max`**: The maximum allowed value for the field.
- **`default_value`**: The default value.
For example:
@ -806,6 +808,7 @@ The `float` field type supports the following additional options:
- **`min`**: The minimum allowed value for the field.
- **`max`**: The maximum allowed value for the field.
- **`default_value`**: The default value.
For example:
@ -839,6 +842,7 @@ The `date` field type supports the following additional options:
- **`min`**: The minimum allowed date (format: a string YYYY-MM-DD)
- **`max`**: The maximum allowed date (format: a string YYYY-MM-DD)
- **`default_value`**: The default value.
For example:
@ -849,7 +853,7 @@ For example:
"title": "Birthdate",
"type": "date",
"min": "1900-01-01",
"max": "2015-01-01",
"max": "2015-01-01"
}
]
...
@ -945,6 +949,7 @@ The `text` field type supports the following additional options:
- **`cols`**: The number of cols to make the input filed.
- **`minlen`**: The minimum allowed length for the field.
- **`maxlen`**: The maximum allowed length for the field.
- **`default_value`**: The default value.
For example:
@ -966,6 +971,7 @@ For example:
### <a name="field_types_password">Password</a>
- **`minlen`**: The minimum allowed length for the field.
- **`default_value`**: The default value.
### <a name="field_types_file">File</a>

@ -22,6 +22,14 @@
"title": "Last name",
"type": "string"
},
{
"name": "birthdate",
"title": "Birthdate",
"type": "date",
"min": "1900-01-01",
"max": "2015-01-01",
"default_value": "1980-02-05"
},
{
"name": "email_address",
"title": "What's your email address?",
@ -37,24 +45,6 @@
"description": "Please check which topics you are interested in",
"script": "job_signup_step2.sh",
"fields": [
{
"name": "first_name",
"title": "First name",
"type": "string",
"hidden": true
},
{
"name": "last_name",
"title": "Last name",
"type": "string",
"hidden": true
},
{
"name": "email_address",
"title": "What's your email address?",
"type": "string",
"hidden": true
},
{
"name": "check_company",
"title": "Negacorp Company news",
@ -154,6 +144,7 @@
"title": "From IP Address",
"type": "string",
"required": true,
"default_value": "192.168.4.",
"min_length": 7,
"size": 15
},
@ -162,7 +153,8 @@
"title": "Expire (days)",
"type": "integer",
"max": 31,
"min": 2
"min": 2,
"default_value": 7
},
{
"name": "network",

@ -18,13 +18,14 @@ class FormDefinition(object):
for validation of the form values.
"""
def __init__(self, name, title, description, fields, script,
output='escaped', hidden=False, submit_title="Submit",
allowed_users=None, run_as=None):
default_value=None, output='escaped', hidden=False,
submit_title="Submit", allowed_users=None, run_as=None):
self.name = name
self.title = title
self.description = description
self.fields = fields
self.script = script
self.default_value = default_value
self.output = output
self.hidden = hidden
self.submit_title = submit_title

@ -111,6 +111,7 @@ class ScriptForm(object):
form['description'],
form['fields'],
script,
default_value=form.get('default_value', ""),
output=form.get('output', 'escaped'),
hidden=form.get('hidden', False),
submit_title=form.get('submit_title', 'Submit'),

@ -280,7 +280,8 @@ class ScriptFormWebApp(RequestHandler):
# Get field-specific parameters
if field['type'] not in ('file', 'checkbox'):
params['value'] = form_values.get(field['name'], '')
default_value = field.get('default_value', '')
params['value'] = form_values.get(field['name'], default_value)
if field['type'] not in ('radio', 'checkbox', 'select'):
params['required'] = field.get('required', False)

Loading…
Cancel
Save