If the value of the select widegt is not within the options choice seems to be empty, even if a value is set.
Is there a workaround for this?
Well, after thinking five minutes:
The workaround is adding the fieldvalue to the options by means of a filter…
Try this:
CHOSEN: <$edit-text field="chosen"/><br>
<$set name="items" filter="[tag[HelloThere]]">
<$let chosen={{!!chosen}}>
<$select field="chosen">
<$list filter="[enlist<items>]"><option><<currentTiddler>></option></$list>
<$list filter="[enlist<items>match<chosen>count[]match[0]then<chosen>!match[]]">
<option><<chosen>></option>
</$list>
</$select>
Notes:
- Line 1 lets you enter an arbitrary value into the “chosen” field
- Line 2 gets a list of possible values (in this example, a list of all tiddlers tagged with “HelloThere”)
- Line 3 gets the current chosen field value as a variable
- Line 4 starts the
$select
widget to set the “chosen” field - Line 5 creates option choices for all list items
- Line 6 is a conditional that says “if the current value is not in the list of items, and is also not a blank value”
- Line 7 adds the option for the chosen value
- Line 8 ends the conditional
- Line 9 ends the
$select
list
enjoy,
-e
3 Likes
And just to fill out @EricShulman’s comprehencive answer I often find a reason to provide a reset option
<option value="">(clear)</option>
- Inside the select widget but outside one of the list widgets use in erics solution.
1 Like