I need to be able to list all fields with an empty value in them and have a button that deletes fields. I also need that same button to match all fields with an @ symbol and delete them as well. I figured out how to delete all fields with the @ symbol, but cannot figure out how to delete fields with no value.
This is what I have so far:
<$button>
<$list filter="[<currentTiddler>fields[]]" variable="field">
<$list filter="[<currentTiddler>get<field>match[@]]" variable="text">
<$action-deletefield $field=<<field>>/>
</$list>
</$list>
Delete Fields
</$button>
The idea is that I add this button to the tiddler $:/core/ui/EditTemplate/fields.
An additional inner list to accompany your delete fields containing “@” would be;
<$list filter="[all[current]!has<field>then<field>]">
<$action-deletefield $field=<<field>>/>
</$list>
However you may be able to combine the filters as the return different results.
<$button>
<$list filter="[<currentTiddler>fields[]]" variable="field">
<$list filter="[all[current]!has<field>then<field>] [<currentTiddler>get<field>match[@]]" variable="text">
<$action-deletefield $field=<<field>>/>
</$list>
</$list>
Delete Fields
</$button>
-
I have tested above with Test Delete fields.json (475 Bytes)
-
You can just tag this tiddler with $:/tags/EditTemplate and optionally add list-before="$:/core/ui/EditTemplate/fields" rather than edit $:/core/ui/EditTemplate/fields
Just a tip, look at the documentation for the has operator the simple form has[fieldname] is true only if the field has a non-blank value. has:field[fieldname] is true whether it has a value OR is blank.
In your case I since we already know the fieldname existed I ask !has<field> which is like " ‘fieldvalue’ Not is not-Blank" (a double negative) or “fieldvalue is blank”.
Another tip; we can use a special form of the field operators show-field[yes] or in your case fieldname[@] but I am not sure its applicable here.