mirror of
https://github.com/markqvist/NomadNet.git
synced 2024-12-26 07:39:26 -05:00
Add Checkbox and Radio Button fields to Micron format
This commit is contained in:
parent
a5aa2097bd
commit
912c510ab2
@ -31,7 +31,7 @@ The data can be `!`[submitted`:/page/input_fields.mu`username|two]`!.
|
|||||||
|
|
||||||
>> Checkbox Fields
|
>> Checkbox Fields
|
||||||
|
|
||||||
`B444`<?|sign_up|1`>`b Sign me up
|
`B444`<?|sign_up|1|*`>`b Sign me up
|
||||||
|
|
||||||
>> Radio group
|
>> Radio group
|
||||||
|
|
||||||
|
@ -1166,6 +1166,10 @@ When the checkbox is checked, it's field will be set to the provided value. If t
|
|||||||
|
|
||||||
`B444`<?|sign_up|1`>`b Sign me up`
|
`B444`<?|sign_up|1`>`b Sign me up`
|
||||||
|
|
||||||
|
You can also pre-check both checkboxes and radio groups by appending a |* after the field value.
|
||||||
|
|
||||||
|
`B444`<?|checkbox|1|*`>`b Pre-checked checkbox`
|
||||||
|
|
||||||
>>> Radio groups
|
>>> 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.
|
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.
|
||||||
|
@ -177,7 +177,8 @@ def parse_line(line, state, url_delegate):
|
|||||||
fv = o["value"]
|
fv = o["value"]
|
||||||
flabel = o["label"]
|
flabel = o["label"]
|
||||||
fs = o["style"]
|
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_name = fn
|
||||||
f.field_value = fv
|
f.field_value = fv
|
||||||
fa = urwid.AttrMap(f, fs)
|
fa = urwid.AttrMap(f, fs)
|
||||||
@ -187,12 +188,13 @@ def parse_line(line, state, url_delegate):
|
|||||||
fv = o["value"]
|
fv = o["value"]
|
||||||
flabel = o["label"]
|
flabel = o["label"]
|
||||||
fs = o["style"]
|
fs = o["style"]
|
||||||
if not "radio_groups" in state:
|
fprechecked = o.get("prechecked", False)
|
||||||
|
if "radio_groups" not in state:
|
||||||
state["radio_groups"] = {}
|
state["radio_groups"] = {}
|
||||||
if not fn in state["radio_groups"]:
|
if fn not in state["radio_groups"]:
|
||||||
state["radio_groups"][fn] = []
|
state["radio_groups"][fn] = []
|
||||||
group = 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_name = fn
|
||||||
f.field_value = fv
|
f.field_value = fv
|
||||||
fa = urwid.AttrMap(f, fs)
|
fa = urwid.AttrMap(f, fs)
|
||||||
@ -200,6 +202,7 @@ def parse_line(line, state, url_delegate):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
columns_widget = urwid.Columns(widgets, dividechars=0)
|
columns_widget = urwid.Columns(widgets, dividechars=0)
|
||||||
text_widget = columns_widget
|
text_widget = columns_widget
|
||||||
# text_widget = urwid.Text("<"+output+">", align=state["align"])
|
# text_widget = urwid.Text("<"+output+">", align=state["align"])
|
||||||
@ -501,6 +504,7 @@ def make_output(state, line, url_delegate):
|
|||||||
field_name = field_content
|
field_name = field_content
|
||||||
field_value = ""
|
field_value = ""
|
||||||
field_data = ""
|
field_data = ""
|
||||||
|
field_prechecked = False
|
||||||
|
|
||||||
# check if field_content contains '|'
|
# check if field_content contains '|'
|
||||||
if '|' in field_content:
|
if '|' in field_content:
|
||||||
@ -526,10 +530,23 @@ def make_output(state, line, url_delegate):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
pass # Ignore invalid width
|
pass # Ignore invalid width
|
||||||
|
|
||||||
|
# Check for value and pre-checked flag
|
||||||
if len(f_components) > 2:
|
if len(f_components) > 2:
|
||||||
field_value = f_components[2]
|
field_value = f_components[2]
|
||||||
|
else:
|
||||||
|
field_value = ""
|
||||||
|
if len(f_components) > 3:
|
||||||
|
if f_components[3] == '*':
|
||||||
|
field_prechecked = True
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
# No '|', so field_name is field_content
|
||||||
field_name = field_content
|
field_name = field_content
|
||||||
|
field_type = "field"
|
||||||
|
field_masked = False
|
||||||
|
field_width = 24
|
||||||
|
field_value = ""
|
||||||
|
field_prechecked = False
|
||||||
|
|
||||||
# Find the closing '>' character
|
# Find the closing '>' character
|
||||||
field_end = line.find('>', backtick_pos)
|
field_end = line.find('>', backtick_pos)
|
||||||
@ -546,6 +563,7 @@ def make_output(state, line, url_delegate):
|
|||||||
"name": field_name,
|
"name": field_name,
|
||||||
"value": field_value if field_value else field_data,
|
"value": field_value if field_value else field_data,
|
||||||
"label": field_data,
|
"label": field_data,
|
||||||
|
"prechecked": field_prechecked,
|
||||||
"style": make_style(state)
|
"style": make_style(state)
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user