Remove an item from Data Tiddler dictionary

57 views
Skip to first unread message

MagoArcade

unread,
Aug 4, 2019, 3:30:58 PM8/4/19
to TiddlyWiki
I'm writing a data tiddler editor, just with add and delete. Can;'t get delete working. Code below:

!Edit Relationship Types
----
Existing Types:


<$list filter="[[$:/_DTrelTypes]indexes[]sort[title]]" variable="key">


</$list>


''Add New:''
<$edit-text tiddler="$:/
temp/EditRelTypes" field="newreltype" tag="input" default="" class='tc-edit-texteditor' placeholder='Type a new relationship type here'/>


<$vars newrelvar={{$:/temp/EditRelTypes!!newreltype}}>


<$button>Add Type


<$action-listops $tiddler="
$:/_DTrelTypes" $index=<<newrelvar>> $subfilter=<<newrelvar>>/>


</$button>


<$button>Delete


<$action-listops $tiddler="$:/
_DTrelTypes" $subfilter="[remove[<<newrelvar>>]]"/>


</$button>


deltiddlr: <<deltiddler>>


</$vars>

I'm happy to have my key and value the same (essentially just need a list)

Would be grateful for a steer


Mark S.

unread,
Aug 4, 2019, 3:36:09 PM8/4/19
to TiddlyWiki
I notice that your  action-listops for deletion doesn't specify an index attribute. Could that be the problem?

MagoArcade

unread,
Aug 4, 2019, 3:38:33 PM8/4/19
to TiddlyWiki
I tried it with both - no difference.

Mark S.

unread,
Aug 4, 2019, 4:19:24 PM8/4/19
to TiddlyWiki
The listops widget was made for adding items to a list field or index value. But since you're adding
items like  myindex=myindex, there isn't really a list field to manipulate. Or rather, the list will always
contain just one item.

Using the action-listop widget with the $filter attribute, I think you could set the $index value to empty. But you
can't remove the index entry entirely.

For deleting the entire item from the dictionary, which seems to be what you want, you can use
the action-setfield widget instead. The code below seems to work.

Good luck!


!Edit Relationship Types
----
Existing Types:


<$list filter="[[$:/_DTrelTypes]indexes[]sort[title]]" variable="key">


</$list>


''Add New:''
<$edit-text tiddler="$:/
temp/EditRelTypes" field="newreltype" tag="input" default="" class='tc-edit-texteditor' placeholder='Type a new relationship type here'/>


<$vars newrelvar={{$:/temp/EditRelTypes!!newreltype}}>


<$button>Add Type


<$action-listops $tiddler="
$:/_DTrelTypes" $index=<<newrelvar>> $subfilter=<<newrelvar>>/>


<
/$button>


<$button>Delete


<$action-setfield $tiddler="$:/
_DTrelTypes" $index=<<newrelvar>> />


</$button>


deltiddlr: <<deltiddler>>


</$vars>


MagoArcade

unread,
Aug 4, 2019, 4:28:43 PM8/4/19
to TiddlyWiki
Brilliant, Mark - I'd never have thought of that given that it's using field manipulation on essentially tiddler text. That's some esoteric TiddlyWIki knowledge you got there!

Thanks again. 
Reply all
Reply to author
Forward
0 new messages