From 6214b2681ee6496df0ef09d7b7075cd52d55722c Mon Sep 17 00:00:00 2001 From: Ferry Boender Date: Sun, 10 May 2015 11:57:33 +0200 Subject: [PATCH] Allow hidden form fields. --- doc/MANUAL.md | 4 ++++ src/scriptform.py | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/doc/MANUAL.md b/doc/MANUAL.md index 766b1a5..83af10c 100644 --- a/doc/MANUAL.md +++ b/doc/MANUAL.md @@ -168,6 +168,10 @@ Structurally, they are made up of the following elements: - **`allowed_users`**: A list of users that are allowed to view and submit this form. **Optional**, **List of strings**. + - **`hidden`**: If 'true', the input field is hidden. This is useful for + pre-filled forms which takes it values from the GET request. + **Optional**, **boolean**. + - **`users`**: A dictionary of users where the key is the username and the value is the plaintext password. This field is not required. **Dictionary**. diff --git a/src/scriptform.py b/src/scriptform.py index 855a87a..49e0fa6 100755 --- a/src/scriptform.py +++ b/src/scriptform.py @@ -66,6 +66,7 @@ html_header = u''' div.form p.form-description {{ font-size: 0.90em; margin: 40px 25px 65px 25px; }} div.form li {{ font-size: 0.90em; list-style: none; }} + div.form li.hidden {{ display: none; }} div.form p.form-field-title {{ margin-bottom: 0px; }} div.form p.form-field-input {{ margin-top: 0px; }} select, @@ -743,12 +744,17 @@ class ScriptFormWebApp(WebAppHandler): field['type']) ) + classes = '' + if 'hidden' in field and field['hidden']: + classes += 'hidden ' + return (u''' -
  • +
  • {title}

    {input} {errors}

  • - '''.format(title=field['title'], + '''.format(classes=classes, + title=field['title'], input=input, errors=u', '.join(errors)))