From 450bc70b723e6c6add6897dbccb40e2060aa5427 Mon Sep 17 00:00:00 2001 From: Ferry Boender Date: Thu, 2 Apr 2015 07:32:25 +0200 Subject: [PATCH] First radio option is selected by default now. --- src/scriptform.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/scriptform.py b/src/scriptform.py index 5c0fb17..73f918d 100755 --- a/src/scriptform.py +++ b/src/scriptform.py @@ -3,7 +3,6 @@ # Todo: # # - How does script_raw check the exitcode? Document this. -# - Radio field type has no correct default value. # - Default values for input fields. # - If there are errors in the form, its values are empties. @@ -472,7 +471,7 @@ class ScriptFormWebApp(WebAppHandler): "password": '', "text": '', "select": '', - "radio": '{2}
', + "radio": '{3}
', } def render_field(field, errors): @@ -497,12 +496,12 @@ class ScriptFormWebApp(WebAppHandler): elif field['type'] == 'password': input = tpl.format(required, field.get('minlen', ''), field['name']) elif field['type'] == 'radio': - input = ''.join( - [ - tpl.format(field['name'], o[0], o[1]) - for o in field['options'] - ] - ) + radio_elems = [] + checked = 'checked' + for option in field['options']: + radio_elems.append(tpl.format(checked, field['name'], option[0], option[1])) + checked = '' # Check first radio option + input = ''.join(radio_elems) elif field['type'] == 'text': rows = field.get('rows', 5) cols = field.get('cols', 80)