WHAT I TRIED:
I've tried various things; my most recent attempt is this:
<$button set=!!test setTo=<$macrocall $name=".js-macro-link" text={{!!test}}/> >Test button</$button>
However, the parser can't seem to handle the angle brackets of the macrocall widget appearing in the middle of the button widget declaration. Everything after the "/>" that closes the macrocall widget appears as WikiText following a blank button.
Before that I tried calling the macro through the standard syntax, and discovered that (unless there's some way to do it that I missed) you can't use a macro call as an element attribute.
It occurred to me that since a ButtonWidget can contain multiple ActionWidgets, that might be the solution - except that there's nothing in the documentation guaranteeing an order in which such widgets execute, so assigning the output of a macro to a temporary tiddler and then copying it back to the original field does not seem to be an option.
PLEASE NOTE:
Please note that I am trying to get an answer to the GENERAL question, not "how do I get the same effect as if I was applying this particular macro?" I am sure that there would be a simple way to apply the effect of THIS macro with template transclusion, but that does not answer my question, because sooner or later I will be using the technique for Javascript macros that do mathematical calculations.
DOCUMENTATION SUGGESTION:
A chart which shows the various forms of data sourcing (plain text, TextReference, macro output, etc.) in columns and then shows in rows what they can and can't be used for (macro parameters, element attributes, etc.) would be useful.
<$set name="js-macro-link-text" value={{!!test}}><$button set=!!test setTo=<<js-macro-link>>>Test button</$button></$set>4) Therefore, you will most often need to use <$set ...> to set a variable to be used by a macro that gets fed to your widget
Right now, though, I still have a problem that's completely blocking me: how do I get the *results* of a macro call into a variable?
The project I'm working on will involve dates. I can write a macro in Javascript which takes a date in TW's format and adds or subtracts a given amount of time. But how can I have TiddlyWiki call that macro *and* store it in a field rather than simply rendering the result on the screen?
From http://tiddlywiki.com/#MacroCallWidget :
<$macrocall $name="italicise" text=<<textMaker "Another macro to generate the text to be italicised">>/>
Does this not work, and it got included as an example without testing? Or, if it does work, why does it work when other attempts to use macros as attributes fail?
3) You can use a macro inside a widget IF it doesn't have a parameter
4) Therefore, you will most often need to use <$set ...> to set a variable to be used by a macro that gets fed to your widget
Mark
On Saturday, October 3, 2015 at 10:49:00 AM UTC-7, Antaeus Feldspar wrote:Or, to express it a different way from the subject line, how can I create a button widget that will:
a) take the current value of a tiddler field;
b) use that current value as a parameter to a macro to calculate a new value; and
c) put that new value back into the tiddler field that was read?WHAT I TRIED:
I've tried various things; my most recent attempt is this:
<$button set=!!test setTo=<$macrocall $name=".js-macro-link" text={{!!test}}/> >Test button</$button>
However, the parser can't seem to handle the angle brackets of the macrocall widget appearing in the middle of the button widget declaration. Everything after the "/>" that closes the macrocall widget appears as WikiText following a blank button.
Before that I tried calling the macro through the standard syntax, and discovered that (unless there's some way to do it that I missed) you can't use a macro call as an element attribute.
It occurred to me that since a ButtonWidget can contain multiple ActionWidgets, that might be the solution - except that there's nothing in the documentation guaranteeing an order in which such widgets execute, so assigning the output of a macro to a temporary tiddler and then copying it back to the original field does not seem to be an option.
PLEASE NOTE:
Please note that I am trying to get an answer to the GENERAL question, not "how do I get the same effect as if I was applying this particular macro?" I am sure that there would be a simple way to apply the effect of THIS macro with template transclusion, but that does not answer my question, because sooner or later I will be using the technique for Javascript macros that do mathematical calculations.
DOCUMENTATION SUGGESTION:
A chart which shows the various forms of data sourcing (plain text, TextReference, macro output, etc.) in columns and then shows in rows what they can and can't be used for (macro parameters, element attributes, etc.) would be useful.
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/b9f31e05-bf09-4170-a63e-5e57225f3cc0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/f0604d54-69de-403a-a749-1c64e66b2279%40googlegroups.com.
<$set name="js-macro-link-text" value={{!!test}}><$button set=!!test setTo=<<js-macro-link>>>Test button</$button></$set>js-macro-link-text" like so:js-macro-link-text");
cheers
BJ
What is the right way to create a button that will read a value from a field, use that value as input to a macro to reach a new value, and then write that value back to the same field?
I'm starting to get a bit discouraged that such a simple goal seems so difficult to achieve.
Am I just taking the completely wrong approach? Is there a different way, other than macros, to do calculations in JavaScript on data stored in tiddlers? If so, where is it documented?
The first time I read Tobias' solution and tried my own based on it, it didn't work for me. I don't know exactly what I was doing wrong (the text of that attempt was lost by a browser crash), but every attempt to call the macro seemed to produce just the text of the macro call, not its result.
Now I understand the solution: write the macro so that any parameters which can't be represented as hard-coded strings are instead accepted via variables. Then use SetWidgets or a VarsWidget around the macro call, and set the parameters with those. Then the macro call can be used as an attribute to the ButtonWidget.
This is the code of my working version:
```
\define add-she-said()
Hey $(add-she-said-text)$ - is what she said.
\end
<$set name="add-she-said-text" value="roll it">
----
<<add-she-said>>
</$set>
<$set name="add-she-said-text" value={{!!test}}>
<$button set=!!test setTo=<<add-she-said>>>Test button</$button>
</$set>
```
Tobias, you're right that the best solution may end up being something other than a macro, but to keep the project going, I have a deep need to be able to update certain data fields easily in great numbers of tiddlers. An imperfect solution now is tons better than a perfect solution in three months.
Tobias, you're right that the best solution may end up being something other than a macro, but to keep the project going, I have a deep need to be able to update certain data fields easily in great numbers of tiddlers. An imperfect solution now is tons better than a perfect solution in three months.
My macro will take a 17-character string as used in a Date field as its first parameter, and as its second, a string indicating an amount of time to increment it ("1d", for instance, would be one day.) It will calculate and return the incremented date. With being able to read, modify, and write back a date values, I can create easy "reschedule" buttons for task tiddlers.
To tell the truth, there are some terrific JS libraries that do all of that and much more, and I was hoping there would be a simple way they might be incorporated into TW5, but if there is, I haven't found documentation for it. Is there such a way? Or has someone already created awesome date-manipulation plugins?
function(datestring, shiftbydays) {
var date = $tw.utils.parseDate(datestring),
result = new Date(date.getTime() + shiftbydays*86400000);
return $tw.utils.stringifyDate(result);
}I haven't tried it though. If anyone tries this, they should be sure to back up their TW. A single mistake can cause the red-block-of-javascript doom to pop up.var format = this.getVariable("format") ;var delay = this.getVariable("delay") ;var ts = this.getVariable("ts") ;