A field of free values, each one a tag: the recipients of a message, the labels of a task. Suggestions help while typing.
Recipients of a message
Suggestions show on focus and narrow as you type; render= draws each one. A tag shows the name, its tooltip the address. variant="ghost": the lines of the message frame the fields.
To
Cc
defrecipients()->None:# ``ghost``: no frame per field — the lines of the message do the work.with(ui.card(padding="none",classes="w-full max-w-xl"),ui.vstack(gap="none",classes="px-4")):fori,(label,value)inenumerate((("To",["[email protected]"]),("Cc",[]))):ifi:ui.divider(gap="none")withui.hstack(gap="sm",align="center"):ui.text(label,color="muted",size="sm",classes="w-6 shrink-0")ui.tags_input(PEOPLE,value=value,render=person,pattern=EMAIL,variant="ghost",placeholder="Add people"iflabel=="To"elseNone)
Free labels
Enter, Tab, « ; » and « , » turn what is typed into a tag; pasting « a, b, c » makes three.
Enter, Tab or a comma adds one.
deffree_labels()->None:withui.form_field(label="Labels",hint="Enter, Tab or a comma adds one.",classes="max-w-sm"):ui.tags_input(["design","backend","customer","urgent"],value=["design"],placeholder="Add a label")
Values that must match
pattern= says what a valid value is. A value that does not match is kept, in red, the reason in its tooltip — the app decides what to do with it.
defchecked_values()->None:withui.form_field(label="Invite by e-mail",classes="max-w-md"):ui.tags_input(value=["[email protected]","not-an-address"],pattern=EMAIL)
A list the page reads
The value is a list in a ClientState: what is around the field follows each tag added or removed.