Setting a field value from within SVG

47 views
Skip to first unread message

c pa

unread,
Nov 21, 2019, 12:21:39 PM11/21/19
to TiddlyWiki
I want to use clickable SVG images from within my Tiddlywiki.
The documentation says to use the foreignobject element to enclose wikitext
This is problematic because it is so difficult to position and size the button to coincide with the drawing element and manage elemnt ordering etc.

I went to MDN and found:

<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
  <circle cx="100" cy="100" r="100" onclick="alert('You have clicked the circle.')" />
</svg>

Does anyone know how I can use an onClick event like this to call a tiddlywiki macro?

I tried onclick="this.wiki.setText('tiddlerName','current-item',null,'test text',null);"

But that doesn't work.... any clues?

Then for extra points... Would it be possible to call a macro with parameters? If I could do that, I could do more fancy things.

Sycom

unread,
Nov 21, 2019, 1:58:51 PM11/21/19
to TiddlyWiki
Hello,

I think you should put your svg image inside a button with an ActionWidget.

See https://tiddlywiki.com/#ActionSetFieldWidget

Cheers

Sylvain
@sycom

Jed Carty

unread,
Nov 21, 2019, 2:12:39 PM11/21/19
to TiddlyWiki
I made some svg things using Snap.svg a while ago, it is probably much more elaborate than you want, but it works. https://ooktech.com/jed/ExampleWikis/SnapSVG/

Although I don't remember a thing about how it works.
Reply all
Reply to author
Forward
0 new messages