triggering action widgets

1,065 views
Skip to first unread message

Neil Griffin

unread,
Jan 4, 2015, 4:58:49 AM1/4/15
to tiddl...@googlegroups.com
Hi all,

The documentation for ActionWidgets on tiddlywiki.com describes the <$button> widget as an example of a widget that can trigger an action widget.  Am I right in thinking that currently it is the only way to trigger an action?  I was hoping to be able to use a <$select> widget to trigger an action-setfield whenever the selected value is changed, but this does not seem to work.

Before I either start implementing a sub-optimal alternative, or attempting to write my own modified widget, does anyone know if there might be an existing solution? Failing that, how hard would it be to add this feature to the <$select> widget (for someone with no experience in modifying widgets, but with a can-do attitude)?

Thanks,

Neil.

Jeremy Ruston

unread,
Jan 4, 2015, 5:08:25 AM1/4/15
to TiddlyWiki
Hi Neil

> The documentation for ActionWidgets on tiddlywiki.com describes the <$button> widget as an example of a widget that can trigger an action widget.  Am I right in thinking that currently it is the only way to trigger an action?

That's correct, only the button widget triggers action widgets at the moment.

> how hard would it be to add this feature to the <$select> widget (for someone with no experience in modifying widgets, but with a can-do attitude)?

It would be fairly straightforward. In the handleChangeEvent handler of the select widget we need to call self.invokeActions(event).

There are a few other widgets that should be enabled, too: link, checkbox, radio and maybe keyboard, edit-*, dropzone.

Best wishes

Jeremy.





--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.
For more options, visit https://groups.google.com/d/optout.



--
Jeremy Ruston
mailto:jeremy...@gmail.com

Neil Griffin

unread,
Jan 4, 2015, 7:30:39 AM1/4/15
to tiddl...@googlegroups.com, jeremy...@gmail.com
Thanks Jeremy.  I'll have a delve when I get a moment.

Jed Carty

unread,
Jan 4, 2015, 1:08:55 PM1/4/15
to tiddl...@googlegroups.com
I am working on a link-fields widget that makes sure that the value of one (or more) field(s) is the same as another field. It still has some problems that I am hoping to fix, but it works. http://inmysocks.tiddlyspot.com/#TW5Utils%20Plugin
I was hoping to add exactly what you are talking about with the select widget to the plugin as well, along with some other hopefully useful modifications.

But make sure to back up anything before you use the plugin. If you use the field=tiddler syntax (which I will hopefully change to tiddler:field when I figure out how) and give it the name of a tiddler that doesn't exist than it can crash your wiki. So be careful.

Felix Küppers

unread,
Jan 4, 2015, 2:23:12 PM1/4/15
to tiddl...@googlegroups.com, jeremy...@gmail.com
 
It would be fairly straightforward. In the handleChangeEvent handler of the select widget we need to call self.invokeActions(event).
There are a few other widgets that should be enabled, too: link, checkbox, radio and maybe keyboard, edit-*, dropzone.
 
I often thought about this. It would be such a great addition!

Tobias Beer

unread,
Jan 4, 2015, 4:22:09 PM1/4/15
to tiddl...@googlegroups.com
I am working on a link-fields widget that makes sure that the value of one (or more) field(s) is the same as another field.

May I ask: Why?

Best wishes, Tobias. 

Jed Carty

unread,
Jan 4, 2015, 8:36:53 PM1/4/15
to tiddl...@googlegroups.com
Tobias,

A few things:

It would make some things a bit more straightforward, like I think I can use it to implement location-based triggers for the interactive fiction engine I made. Most of what it does could be done using the set widget with a filter using the get operator, but I am hoping that just being able to say 'make this field always equal that field' will be simpler for people to use.

I would like to eventually make it so that instead of specifying a single value it will use a data tiddler to set multiple fields to different values. Once again, that could probably be done using the set widget and filters, but I think that this would be more straight forward and understandable.

With the sumfield2 and prodfield2 widgets from the MathyThing plugin I was able to iterate over a list of tiddlers and perform the sums in each tiddler, so I am hoping to be able to do something similar and add a field and set its value in an arbitrary list of tiddlers. I think that someone else mentioned wanting to be able to do this.

But mainly, I am learning javascript and I am trying to make whatever pops into my head. So even if it never has a real use I am hoping to learn enough to build useful things at some point. This only took me a few hours and I learned a lot about how javascript is used in tiddlywiki and how to prevent errors when a widget is passed invalid input values.

Jed Carty

unread,
Jan 4, 2015, 11:21:50 PM1/4/15
to tiddl...@googlegroups.com
I made an example of how the link-fields widget can be used to have a select widget set multiple fields to different values simultaneously. It is not a particularly elegant solution, but it works. Hopefully I will be able to find a way to let it use a data tiddler to define the values, but I haven't yet. And I think I tracked down everything in the link-fields widget that would cause a wiki to crash, but as always back up your wiki to be safe.

Here is the example:

http://inmysocks.tiddlyspot.com/#Using%20the%20link-fields%20widget%20to%20make%20a%20select%20widget%20set%20multiple%20fields%20to%20separate%20values

Tobias Beer

unread,
Jan 5, 2015, 12:07:31 PM1/5/15
to tiddl...@googlegroups.com
Hi Jed,
 
'make this field always equal that field' will be simpler for people to use

You still have not explained why you want to do that. Or did I miss it?

Is it that you have a tiddler or template foo and upon button press you want the value bar at tiddler baz to be set to the value of bar at foo. Or is it rather that you want that value durably linked / synced and, if so, why?

Best wishes, Tobias.

Tobias Beer

unread,
Jan 5, 2015, 12:16:50 PM1/5/15
to tiddl...@googlegroups.com
Hi Jed,

In your example with this looong title...


I find a tag pointing to...


I have absolutely no idea what this does. Could be I am a little lazy to try and reverse engineer the behavior by looking at the examples. ^^

Also, where is that source code of said list-fields widget? Are you the author?

Best wishes, Tobias.

Jed Carty

unread,
Jan 5, 2015, 1:17:47 PM1/5/15
to tiddl...@googlegroups.com
A set of durably linked fields could make settings like I have in the contacts database I made easier to manage. But it looks like the biggest uses are from using it in a sort of oblique fashion. Like setting the values of a set of fields on a button press like in this example: http://inmysocks.tiddlyspot.com/#Update%20Multiple%20Fields%2FTiddlers%20%28sort%20of%29%20on%20a%20Button%20Press%20-%20link-fields%20Widget

I wrote the widget, the code is here: https://github.com/inmysocks/TW5-TW5Utils

http://inmysocks.tiddlyspot.com/#My%20Plugins that shows a list of the plugins I made with versions numbers and links to the tiddlers explaining them. Or at least tiddlers that are supposed to explain them, I haven't done a very good job with that.

Looking at how the plugins section of my table of contents is organized currently I see that I need to rethink my tiddler naming. And make better documentation. I normally navigate my wiki using the table of contents which is why the horribly long tiddler names don't cause me too much trouble, but this doesn't seem to be the common way of doing things so I will see about cleaning that up.

And the purpose of making one field always equal another field is that it could simplify using templates to display tiddlers, if you wanted each of the displayed tiddlers to reference a field in an other tiddler you could just use {{tiddlerToReference!!field_to_reference}}, or with this just {{!!field_to_reference}} and have all of the displayed tiddlers have their fields linked to a single settings-type tiddler where you could easily change the values. I don't know if this has practical value since it doesn't really simpliy things very much, but it was what I was thinking when I wrote the widget. The only time that I can think of where that would have a use for the basic case of 'make this field equal that field' is for the 'Resize tiddlers' button my wiki has, now I can change it so that you only need to set one value instead of needing to change both individually.

Tobias Beer

unread,
Jan 5, 2015, 8:36:53 PM1/5/15
to tiddl...@googlegroups.com
Hi Jed,

By the way, looking at...


You might benefit from this...

<$select field='foo'>
<$list filter="1 2 3 4 5 6">
<option><<currentTiddler>></option>
</$list>
</$select>

''foo
:'' {{!!foo}}

Best wishes, Tobias.

Tobias Beer

unread,
Jan 5, 2015, 8:41:56 PM1/5/15
to tiddl...@googlegroups.com
As for "linking fields", instead of having a dedicated link-fields widget...

<$link-fields
$sourcetiddler=sourceTiddler
$sourcefield=source_field
$storetiddler=storeTiddler
$storefield=store_field/>

...why not use...

title:sourceTiddler
source_field
:foo

...and then...

title:storeTiddler
store_field
:{{sourceTiddler!!source_field}}

?

Jed Carty

unread,
Jan 5, 2015, 10:37:08 PM1/5/15
to tiddl...@googlegroups.com
Tobias,

In that context there isn't really any benefit other than a possible very small simplification. But it can be used to set the value of a field to something other than what the source field is set to.

I have been able to do two things that I have wanted to be able to do with tiddlywiki because of it:
*Using it I can make a single select widget set multiple fields to different values, and the fields can be picked using a filter. This can be triggered either when the select widget changes or on a button press. The fields don't have to be the same value as the source field. http://inmysocks.tiddlyspot.com/#link-fields%20Widget%20-%20Set%20Multiple%20Fields%20Using%20Select and http://inmysocks.tiddlyspot.com/#link-fields%20Widget%20-%20Update%20link-fields%20on%20a%20Button%20Press
*I can use it to search and replace over the content of all fields in all tiddlers in a wiki. http://inmysocks.tiddlyspot.com/#links-field%20Widget%20%20-%20Search%20and%20Replace%20Field%20Contents

The basic 'make this field equal that field' isn't very useful by itself, but what you can do with it seems to be pretty powerful and goes beyond what you can do with the simple transclusion.

Tobias Beer

unread,
Jan 6, 2015, 5:26:34 AM1/6/15
to tiddl...@googlegroups.com
Hi Jed,
 
The basic 'make this field equal that field' isn't very useful by itself, but what you can do with it seems to be pretty powerful and goes beyond what you can do with the simple transclusion.

It's slowly dawning on me now. ^^

Perhaps the "link" bit of the widget name confused me a little, as I was thinking in terms of establishing a permanent bond.
However, it's really more a set type of action... and yes, that is quite useful, indeed.

However, doesn't $action-setfield cater for this very need?


And, if not, why wouldn't it?

Best wishes, Tobias.

Neil Griffin

unread,
Jan 10, 2015, 7:31:44 PM1/10/15
to tiddl...@googlegroups.com, jeremy...@gmail.com
Coming back to the original subject of this thread, after a fair bit of poking around I managed to figure out how things work sufficiently to get triggering from a select widget working.  It was a bit more complicated than just adding this.invokeActions(event) to handleChangeEvent because (I eventually figured out), the contents of the select widget are buried at the grandchild level rather than being immediate children.  To fix this, I also had to modify the invokeActions() function in widget.js so that if the children fail to handle the event, it gets passed on to the children of the first child.  I might try to generalise to all grandchildren later, in which case it might also fix the problem I raised in a separate thread (https://groups.google.com/forum/#!topic/TiddlyWiki/6Q6TrAOBnFI).

However, I have a new problem, as you can see from this demo:
http://ng110.tiddlyspot.com/#trigger%20demo

It seems that the value attribute of the action-setfield widget is always evaluated before the action has been completed, which means that if I am picking up the field controlled by the select widget, then I always get the old value.  Anyone have an idea on how to pick up the new value?

Cheers,

Neil.

Jeremy Ruston

unread,
Jan 11, 2015, 4:05:32 AM1/11/15
to Neil Griffin, TiddlyWiki
>  the contents of the select widget are buried at the grandchild level rather than being immediate children

Why is that happening? The action widgets are supposed to be the immediate children of the triggering widget. There is a proposal to extend things so that all descendent action widgets are triggered, but that's not how it works at the moment.

> It seems that the value attribute of the action-setfield widget is always evaluated before the action has been completed, which means that if I am picking up the field controlled by the select widget, then I always get the old value.  Anyone have an idea on how to pick up the new value?

That's correct; at the point that the action-setfield widget is triggered the target tiddler will have been written, but the associated refresh cycle won't have occurred, and so the action-setfield widget itself won't have been refreshed so that it's attributes reflect the new value.

I think you'll need to run a refresh of the children of the select widget before invoking the action.

Best wishes

Jeremy.





Neil Griffin

unread,
Jan 11, 2015, 12:43:12 PM1/11/15
to tiddl...@googlegroups.com, ngrif...@gmail.com, jeremy...@gmail.com


On Sunday, 11 January 2015 09:05:32 UTC, Jeremy Ruston wrote:
>  the contents of the select widget are buried at the grandchild level rather than being immediate children

Why is that happening? The action widgets are supposed to be the immediate children of the triggering widget. There is a proposal to extend things so that all descendent action widgets are triggered, but that's not how it works at the moment.

I don't know.  I'm still learning this stuff!  But I should clarify that it's not just the action widget, but also the option nodes that are at the grandchild level.  There is a single node at the child level - I'm not sure how to look at what that is.

I am tempted to try to implement triggering of all descendents.  Is there a practical reason why the proposal you mention hasn't been implemented, or is it just because no-one has gotten around to doing it yet?
 
> It seems that the value attribute of the action-setfield widget is always evaluated before the action has been completed, which means that if I am picking up the field controlled by the select widget, then I always get the old value.  Anyone have an idea on how to pick up the new value?

That's correct; at the point that the action-setfield widget is triggered the target tiddler will have been written, but the associated refresh cycle won't have occurred, and so the action-setfield widget itself won't have been refreshed so that it's attributes reflect the new value.

I think you'll need to run a refresh of the children of the select widget before invoking the action.

I'll see if I can figure out how to do that.  However, for my application, which is a bit more complicated than my demo tiddler, I think this might not be adequate.  I might try to write a new bespoke select widget that also does what I am currently doing with a js macro and the action-setfield widget.

Cheers,

Neil.

Jeremy Ruston

unread,
Jan 11, 2015, 3:05:19 PM1/11/15
to Neil Griffin, TiddlyWiki
Hi Neil

I'll see if I can figure out how to do that.  However, for my application, which is a bit more complicated than my demo tiddler, I think this might not be adequate.  I might try to write a new bespoke select widget that also does what I am currently doing with a js macro and the action-setfield widget.

Yes, I think that may be the best way to proceed,

Good luck!

Best wishes

Jeremy
 

Cheers,

Neil.

Stacy Cunningham

unread,
Apr 3, 2016, 10:34:18 PM4/3/16
to TiddlyWiki
I wanted to post because I wanted something non-button with the Action Widgets and I ended up solving it. So then it'd be helpful to someone else (or me again, in needing to look this up again in the future!).

I wanted to be able to use action-setfield with the Link widget. I added
this.invokeActions(event);

to be the first line of handleClickEvent in $:/core/modules/widgets/link.js and it works like a charm.


All the best,
Stacy

Andrew Whiting

unread,
Jun 28, 2016, 4:26:19 PM6/28/16
to TiddlyWiki
Hi Stacy, 

Would something along these lines work for me? I created a simple macro that uses the Link Widget to create a new tiddler but I would like the created tiddler to have several tags. I wanted to use action-setfield but don't know how to trigger it without using a button (which I don't want to do).

It seems like your solution would work for me but I am not a programmer (at all) and really don't know what I am doing!

Thanks!

Andrew

codacoder...@outlook.com

unread,
Jun 28, 2016, 5:22:31 PM6/28/16
to TiddlyWiki, ngrif...@gmail.com, jeremy...@gmail.com


On Sunday, January 11, 2015 at 3:05:32 AM UTC-6, Jeremy Ruston wrote:
>  the contents of the select widget are buried at the grandchild level rather than being immediate children

Why is that happening? The action widgets are supposed to be the immediate children of the triggering widget.

Probably because of this or similar:

<$select>

<option>1</option>
<option>2</option>
<option>3</option>
</$select>



which produces this (unusable) html

<select><p><option>1</option>....</p></select>


@Neil - take care with whitespace in TW5, it's not as "insignificant" as you may think.

@Jeremy: I think that's a bit too fragile - perhaps the docs should make people more aware. Of course, embedded whitespace pretty much anywhere else in the block is fine:


<$select>
<option>1</option>


<option>2</option>
<option>3</option>


</$select>


^ works.

HTH


Jeremy Ruston

unread,
Jun 29, 2016, 3:21:31 AM6/29/16
to codacoder...@outlook.com, TiddlyWiki, ngrif...@gmail.com
Hi Codacoder

You’re correct about the extraneous paragraph tags but I don’t think it’s the problem here: shortly after the message below we changed the core so that action widgets do not have to be an immediate child of the triggering widget:


Best wishes

Jeremy

codacoder...@outlook.com

unread,
Jun 29, 2016, 3:31:36 PM6/29/16
to TiddlyWiki, codacoder...@outlook.com, ngrif...@gmail.com
Well, it's hard to say unless Neil comes back to clarify. All we have is his original statement:


> the contents of the select widget are buried at the grandchild level rather than being immediate children

which led me down the path of P tags.
Reply all
Reply to author
Forward
0 new messages