diff --git a/nomadnet/examples/various/input_fields.py b/nomadnet/examples/various/input_fields.py index 663dc93..5d1eccc 100644 --- a/nomadnet/examples/various/input_fields.py +++ b/nomadnet/examples/various/input_fields.py @@ -31,7 +31,7 @@ The data can be `!`[submitted`:/page/input_fields.mu`username|two]`!. >> Checkbox Fields -`B444``b Sign me up +`B444``b Sign me up >> Radio group diff --git a/nomadnet/ui/textui/Guide.py b/nomadnet/ui/textui/Guide.py index 48dfb56..ba6c4d5 100644 --- a/nomadnet/ui/textui/Guide.py +++ b/nomadnet/ui/textui/Guide.py @@ -1166,6 +1166,10 @@ When the checkbox is checked, it's field will be set to the provided value. If t `B444``b Sign me up` +You can also pre-check both checkboxes and radio groups by appending a |* after the field value. + +`B444``b Pre-checked checkbox` + >>> Radio groups Radio groups are another input that lets the user chose from a set of options. Unlike checkboxes, radio buttons with the same field name are mutually exclusive. diff --git a/nomadnet/ui/textui/MicronParser.py b/nomadnet/ui/textui/MicronParser.py index 7668ecf..05ded7a 100644 --- a/nomadnet/ui/textui/MicronParser.py +++ b/nomadnet/ui/textui/MicronParser.py @@ -177,7 +177,8 @@ def parse_line(line, state, url_delegate): fv = o["value"] flabel = o["label"] fs = o["style"] - f = urwid.CheckBox(flabel, state=False) + fprechecked = o.get("prechecked", False) + f = urwid.CheckBox(flabel, state=fprechecked) f.field_name = fn f.field_value = fv fa = urwid.AttrMap(f, fs) @@ -187,12 +188,13 @@ def parse_line(line, state, url_delegate): fv = o["value"] flabel = o["label"] fs = o["style"] - if not "radio_groups" in state: + fprechecked = o.get("prechecked", False) + if "radio_groups" not in state: state["radio_groups"] = {} - if not fn in state["radio_groups"]: + if fn not in state["radio_groups"]: state["radio_groups"][fn] = [] group = state["radio_groups"][fn] - f = urwid.RadioButton(group, flabel, state=False, user_data=fv) + f = urwid.RadioButton(group, flabel, state=fprechecked, user_data=fv) f.field_name = fn f.field_value = fv fa = urwid.AttrMap(f, fs) @@ -200,6 +202,7 @@ def parse_line(line, state, url_delegate): + columns_widget = urwid.Columns(widgets, dividechars=0) text_widget = columns_widget # text_widget = urwid.Text("<"+output+">", align=state["align"]) @@ -501,6 +504,7 @@ def make_output(state, line, url_delegate): field_name = field_content field_value = "" field_data = "" + field_prechecked = False # check if field_content contains '|' if '|' in field_content: @@ -526,10 +530,23 @@ def make_output(state, line, url_delegate): except ValueError: pass # Ignore invalid width + # Check for value and pre-checked flag if len(f_components) > 2: field_value = f_components[2] + else: + field_value = "" + if len(f_components) > 3: + if f_components[3] == '*': + field_prechecked = True + else: + # No '|', so field_name is field_content field_name = field_content + field_type = "field" + field_masked = False + field_width = 24 + field_value = "" + field_prechecked = False # Find the closing '>' character field_end = line.find('>', backtick_pos) @@ -546,6 +563,7 @@ def make_output(state, line, url_delegate): "name": field_name, "value": field_value if field_value else field_data, "label": field_data, + "prechecked": field_prechecked, "style": make_style(state) }) else: