Two questions about the $list widget

Hi, two quick questions (which I hope are very stupid) :grin:

• The first one: Is it possible to do a kind of “not emptyMessage” in an easy way? (Pretty much the opposite of emptyMessage, the message should appear before the output of $list, only if it’s not empty)

I thought about doing something using “count” and a filter same as the one used in the $list widget but maybe there are smarter ways to do it.

I’m working on something like this:

<$list filter="[tag[Example]]" emptyMessage='No tiddler tagged with "Example"'>
<$fieldmangler>
<$button tooltip="Remove tag" class='tc-btn-icon' message="tm-remove-tag" param="Example">{{$:/core/images/close-button}}</$button>
</$fieldmangler><$link to={{!!title}}><$view field=title/></$link><br>
</$list>

That would be:


And I would like to put a message that appears if the list has at least one element (e.g. “Click on “x” to remove the tag.”)

• And the other question is, can that list be sortable with a drag and drop?
For now to handle the order of some tags I’m using the list-tagged-draggable macro or the tag-pill directly. But I would like it if it were possible to combine the drag and drop convenience that list-tagged-draggable provides with the flexibility of a $list widget, which allows me for example to put buttons next to list items.
Is it possible?

-Sam

For the first question, you can add a second list:

<$list variable=ListMsg filter="[all[tiddlers+shadows]tag[Example]first[]]">Click on “X” to remove the tag</$list>
1 Like

Hi @SnapSam,

Here is a working example:

Create a tiddler called mytemplate with this text:

<$button>{{$:/core/images/close-button}}</$button> <$link/>

And another tiddler with this text:

<$let mytag="Macros">

<$list filter="[tag<mytag>first[]]" variable="none">

Your header here...
<$macrocall $name="list-tagged-draggable" tag=<<mytag>> itemTemplate="mytemplate" />
</$list>
</$let>

And you have a sortable list with buttons!

Fred

1 Like

Thanks for the replies, they look promising. Unfortunately now I have to go to bed, I’ll do some better tests tomorrow (but in the meantime I wanted to thank you). :grinning:

Here is an example I built as a reference for this kind of list;

\define lister(filter)
<$let total-items={{{ $filter$ +[count[]] }}}>
<$list filter="$filter$" emptyMessage="No items" counter=item>
   <$list filter="[<item>match[1]]" variable=~>Before list only if 1 or more items, total=<<total-items>><br></$list>
   <$link/><br><!-- every-item -->
   <$list filter="[<item>match<total-items>]" variable=~>After list</$list>
</$list>
</$let>
\end
<<lister "[tag[TableOfContents]]">>
  • Its in a macro so I can profide the filter once and reference it twice to drive the count and the list.
  • It also determins the total so it can display after the last as well
  • count match 1 is the first or heading.
  • Yes, and if I can find my previouse notes I will share it, however always remember TiddlyWiki often documents itself, the list-tagged-draggable macro is defined in $:/core/macros/list although these macros look a little more complex because they are defined for general use.
  • You could copy the macro definition, give it a new name and add the above code without fully understanding the code.
2 Likes

I apologize for the late reply, I was able to test what you proposed, and I’m at a fairly good place now, and thanks again to all of you.

As for the first question, it is solved. I thought about using a count too, but not in the way you showed me, which is very intuitive. (and also better since I can can put the message in any position i want)
As far as drag and drop is concerned, I’m not quite where I want to be yet.

While I could probably go with the itemTemplate way, I’m not really convinced it’s the best solution for me, in fact for my needs I’d have to create a lot of tiddlers to use only as templates (which are easier to lose track of or modify)
I wish there was a solution that worked in a single tiddler, so as to change the code on a case-by-case basis.

It’s a good idea. I already had looked at the tiddler $:/core/macros/list, and it worries me because the fact that list-tagged-draggable is defined in two \defines “bloks” (?) and I think it will take me a while to decipher them. But if you think I can do it even without understanding everything, I will definitely try.

If it’s not too much trouble that would be great (but if it would take long, please don’t bother)

1 Like