select word from list in dropdown/SelectWidget and create new tiddler with same title [TW5]

436 views
Skip to first unread message

aaron....@gmail.com

unread,
Nov 10, 2015, 12:43:14 AM11/10/15
to tiddl...@googlegroups.com
Hi all,

I'm only a few days into using TiddlyWiki, so please pardon my ignorance.

This is what I am trying to do

  1. make a drop down list populated dynamically based on tags - I have been successful in doing this.
  2. create a button that when clicked, created a new draft widget with the a title that has the words chosen in 1 as part of its title (but not exactly it, it has some words added to what was selected).


This is the macro I have so far:


\define newHereButtonTags()
[[$(currentTiddler)$]]
\end

\define testWhy()
<$view tiddler=<<qualify "select-profile">>>
\end

\define newHereButton()
<$button>
<$action-sendmessage
  $message="tm-new-tiddler"
title=<<testWhy>>
  tags=<<newHereButtonTags>> />
<$list filter="[<tv-config-toolbar-icons>prefix[yes]]">
{{$:/core/images/chevron-up}}
</$list>
</$button>
\end

<$select tiddler=<<qualify "select-profile">> default=''>
<$list filter='[sort[title]tag[JustSOmeTags]]'>
<option value=<<currentTiddler>>><$view field='title'/></option>
</$list>
</$select>


<<newHereButton>>
<<testWhy>>


I created the dropdown list, it is correctly populated with the tags [justsomeTags]


What happens is that when I press the button <<newHereButton>>, it does indeed create a new draft widget, and it tags it automatically with the title of the $(currentTiddler)$.


However, for the life of me I can't figure out why the title of the draft is not getting fetched properly. What I am getting is something like: <$view tiddler=<<qualify "select-profile">>> as the title.


The ultimate goal is to have the title of the new tiddler to be: " title of the parent tiddler (the one that has the button)" + appended text based one what was selected using the selectWidget drop down list.



Tobias Beer

unread,
Nov 10, 2015, 3:18:56 AM11/10/15
to tiddl...@googlegroups.com
Hi aaron,

There are a few issues here.
  1. make sure not to confuse the terms widget and tiddler, i.e. there are no "draft widgets" in the sense you described it
  2. you can't use the ViewWidget in a macro like that
    • the documentation would probably benefit from mentioning that
    • macros simply do text-substitution, no (evaluation via) wikification
    • what you need to use instead is to get the selected option and save it into a variable using the SetWidget
      • and to wrap your create button with all that to make the variable available to its scope
  3. some examples for the SelectWidget on tiddlywiki.com specify state tiddlers that are not system tiddlers, a pattern you adopted
    • this is a poor design choice as it pollutes the tiddler space
    • any such state should be put either under $:/temp/some-select, or at best: $:/state/some-select, never just some-select
    • so, someone should update those documentation tiddlers
  4. there's a bug in the current release 5.1.9 where the set widget won't refresh properly, so changing what's selected won't update any variable assignments based on that
\define the-tags()
foo bar
\end

\define the-title()
$
(currentTiddler)$ $(selected)$
\end

\define create-new(title)
<$button>
<$action-sendmessage $message="tm-new-tiddler"
  title
=<<the-title>>
  tags
=<<the-tags>> />

<$list filter="[<tv-config-toolbar-icons>prefix[yes]]">
{{$:/core/images/new-button}}
</$list>
</
$button>
\end

<$select tiddler=<<qualify "$:/temp/select-profile">> default=''>
<$list filter='[tag[HelloThere]sort[title]]'>

<option value=<<currentTiddler>>><$view field='title'/></option>
</$list>
</
$select>

<$set name="state" value=<<qualify "$:/temp/select-profile">>>
<$set name="selected" filter="[<state>get[text]]">
<<create-new>>
</$set>
</
$set>

Trying this out has one more core problem which is that we do not have a way yet to tell a filter to not return a string of "listified" titles but a plain string. What does that mean? It means that if [<state>get[text]] returns a title that has spaces in it, it will be returned as [[the title]] instead of just the title... which obviously breaks your title pattern in that you do not want any double square brackets in it.

A solution to the problem is proposed in this issue which thus appears crucial with respect to the usability of the SelectWidget:

#2057 list accessors for variables and text references
https://github.com/Jermolene/TiddlyWiki5/issues/2057

An already working solution would be to adopt a pull request I already made, but which has so far been discarded in favor of the not yet implemented #2057:

#2035 parameter "format" for set widget
https://github.com/Jermolene/TiddlyWiki5/pull/2035

Here you would be able to simply do...

\define the-tags()
foo bar
\end

\define create-new(title)
<$button>
<$action-sendmessage $message="tm-new-tiddler"
 title
=<<new-title>>
 tags
=<<the-tags>> />

<$list filter="[<tv-config-toolbar-icons>prefix[yes]]">
{{$:/core/images/new-button}}
</$list>
</
$button>
\end

<$select tiddler=<<qualify "$:/temp/select-profile">> default=''>
<$list filter='[tag[HelloThere]sort[title]]'>

<option value=<<currentTiddler>>><$view field='title'/></option>
</$list>
</
$select>

<$set name="state" value=<<qualify "$:/temp/select-profile">>>
<$set name="new-title" filter="[<currentTiddler>] — [<state>get[text]]" format="text">
<<create-new>>
</$set>
</
$set>

Eventually, when all this is fixed and released, the SelectWidget documentation should show examples of how to actually use a selected option, e.g. in a macro as you do, rather than just show how it all writes some selected state to some state tiddler and how we can display that somewhere else.

Best wishes,

— tb

aaron....@gmail.com

unread,
Nov 10, 2015, 4:00:34 AM11/10/15
to TiddlyWiki
Dear Tobias,

Thank you for kindly taking the time to review this issue. I have quite literally spent the last 4-5 hours trying to get around this issue... in the process I learned a lot about customizing TW5, but ultimately felt defeated as I couldn't reason my way through the macro documentation to a solution.

I'm going to upgrade to the pre-release, and try out your recommendations tomorrow.

Your help is much appreciated
Eventually, when all this is fixed and released, the SelectWidget documentation should show examples of how to actually use a selected option, e.g. in a macro as you do, rather than just show how it all writes some selected state to some state tiddler and how we can display that somewhere else.

Best wishes,

— tb

Tobias Beer

unread,
Nov 10, 2015, 4:43:57 AM11/10/15
to TiddlyWiki
Hi aaron,

I have updated my last comment with an example that makes use of an already working modification to the set widget, which, however has not been accepted as a pull request so far.

Best wishes,

— tb
Reply all
Reply to author
Forward
0 new messages