Select parts

This example shows how to use the lower level API to create a more complex select box with optgroups and help text. It also can be used, when select options are not represented by an iterable of {"value": VALUE, "text": LABEL} objects.

select_box accepts the same arguments as select, except for options and selected. These parameters are handled by code responsible for rendering select_option components.

{%- call ui.util.call(show_example) -%} {%- raw %} {%- set help_text = ui.field_info("Help text") -%} {%- call ui.util.call(ui.select_box, label="Complex select", nested_content=help_text) -%} {%- set values = range(10) -%} {%- for num in values|select("even") -%} {{ ui.select_option(num, value=num) }} {%- endfor %} {%- for num in values|select("odd") -%} {{ ui.select_option(num, value=num, selected=num==7) }} {%- endfor %} {%- endcall %} {%- endraw %} {%- endcall %}