<$select tiddler="stemp" field="mychoice" default="One">
<$list filter="One Two Three Four Five" >
<option value=<<currentTiddler>>><$view field='title'/></option>
</$list>
</$select>
Save, see the result
The select widget works as expected and shows the default value
Play with Select and then open stemp and delete the value of mychoice field, one expect to see the default value, but $select shows nothing!
I am not so sure how you make use of the default when the field is empty, but I tend to use the default just to point to the setting, possibly a waste of time.
<$select tiddler="stemp" field="mychoice" default={{stemp!!mychoice}}>
<$list filter="One Two Three Four Five" >
<option value=<<currentTiddler>>><$view field='title'/></option>
</$list>
</$select>
I suppose code elsewhere may behave as if the default was selected when the field is empty.
Maybe you can wrap the whole thing in a listwidget that tests if the field is empty or doesn’t exist. And the output from this widget is the default value in the selectwidget.
$select will show an empty choice if the contents of the existing field does not match one of the options. You could write “Six” into mychoice and would get the same result. The default attribute only guards against missing fields / tiddlers. As it says so in the docs, it’s probably by design.
You could make the empty field one of the options and have the $select show arbitrary text for it:
<$select tiddler="stemp" field="mychoice " default="One">
<option disabled value="">The field is empty.</option>
<$list filter="One Two Three Four Five" >
<option value=<<currentTiddler>>><$view field="title" /></option>
</$list>
</$select>
I can’t tell if this would be of any use in your scenario. Whereever you actually use the value of mychoice, you’d have to decide what to do with an empty field, too. The selection “The field is empty.” is purely a visual hint for the user, the actual value remains an empty string (that you could check for with is[blank]).
Have a nice day
Yaisog
PS: There is an error in the docs. In example “Simple List with Placeholder Value” it says “Note that the targeted field must be empty, or not exist, for the placeholder to show in the widget”, which, as one can easily test oneself, is not the case.
I am convinced this is a bug or outside the design specification;
When the select widget says “default Default value to be used if the tiddler, field or index specifies a missing value” it miss-interprets an empty field as not missing.
However unless you empty the field outside of the select widget it is not a fault.
This may be answered by core developers. They may differentiate between a blank filed and a missing field.
What we asked here is to interpret a blank field as missing.
@jeremyruston
See the above example: The code generates a field with a trailing space: mychoice . (Note to the blank at the end of name! This is highly error prone!
I cannot remember, but I think you discussed this and you recommended to trim the field names before set!
The $select creates a field with trailing space i.e. field="mychoice ", most of the time this is by mistake, author added a leading or trailing spaces.
The problem here is the attribute field="my choice " has a space at the end of the value.
This is tricky to fix.
In general, I think that the user interface should try to help people avoid shooting themselves in the foot, and so it makes sense to for example trim field names and values.
Limiting the underlying primitives so that they cannot for example create a field that ends in whitespace sounds just as reasonable, but can actually lead to subtle problems. For example, it would mean that it would be possible to encounter the situation where we assign a value to a field but that the field doesn’t end up with the desired value, and so subsequent comparisons with the field contents will not match.