I want to drag plain text (sometimes HTML) vocabulary term-definition to create a tiddler with term as title and definition as content. If the tiddler exists, the new content is appended to the existing tiddler otherwise create new. (keeping only the text. )
My code creates a new tiddler the first time. On second try it creates yet another tiddler -with the same name. What am I doing wrong?
\define vocabSplitPattern() [¦|\/]
\define droppable-text-actions()
/* use vocabSplitPattern() [¦|\/] to split at ¦ or / */
<$wikify name=import-text text=<<actionTiddler>>>
<$vars newTitle={{{ [<import-text>splitregexp<vocabSplitPattern>first[]] }}}
newDefn={{{ [<import-text>splitregexp<vocabSplitPattern>last[]] }}}
lf="""
<hr/>
""">
<!-- If tiddler exists, append new definition -->
<$list filter="[<newTitle>has[text]]" variable="oldText">
<$vars oldText={{{ [<currentTiddler>get[text]] }}} >
<$action-setfield $tiddler=<<currentTiddler>> text={{{ [<newDefn>addsuffix<oldText>] }}} />
<$action-navigate $to=<<currentTiddler>>/>
</$action-setfield>
</$vars>
</$list>
<!-- If tiddler does not exist, create it -->
<$list filter="[<newTitle>!has[title] ]">
<$action-createtiddler $basetitle=<<newTitle>> $template=<<actionTiddler>> text=<<newDefn>> tags="vocab" >
<$action-navigate $to=<<createTiddler-title>>/>
</$action-createtiddler>
</$list>
</$vars>
</$wikify>
\end
<$droppable actions=<<droppable-text-actions>>>
<$button style="width:10em;height:3em;">Drop vocab here</$button>
</$droppable>
Two separate tiddlers have been created with the same title. I’m expecting to keep the first tiddler and append the content which should look like this:
This is very nice. I’ve not done much drag-and-drop in TW. But I always had the impression that it was fiddly and complex. This makes it look quite simple. Thanks for the instructional post!
One very minor question: Why do you choose to use two opposite conditions rather than else?
There are several possibilities to optimize the whole thing. I did use a similar structure as the original code. There should be a possibility to use 2 times the action-createtiddler widget instead of action-setfield.
I tried again on a new empty on Tiddlyhost and it now works.
I tried again on my wiki and it now works.
Not sure why it was misbehaving.
@Scott_Sauyet Combining the if statements with else also works. I suspect he kept it that way since my original list filter code had two separate checks.
So it does! For some reason, I only skimmed the original post, probably because it was asking about drag-and-drop, and I don’t really have any insight to add about that. But it looks like your post already had the simple-looking drag-and-drop code. So thank you too!