Parsing to return action-setfield #5783
Replies: 4 comments 2 replies
-
What type of object is needlesList? If it is not a string, then the
set-action will fail.
```
value : {type: "string", value: needlesList.toString()}
```
That might work?
See the $action-setfield widget code:
https://tiddlywiki.com/#%24%3A%2Fcore%2Fmodules%2Fwidgets%2Faction-setfield.js
```
/*
Invoke the action associated with this widget
*/
SetFieldWidget.prototype.invokeAction = function(triggeringWidget,event) {
var self = this,
options = {};
options.suppressTimestamp = !this.actionTimestamp;
if((typeof this.actionField == "string") || (typeof this.actionIndex
== "string") || (typeof this.actionValue == "string")) {
this.wiki.setText(this.actionTiddler,this.actionField,this.actionIndex,this.actionValue,options);
}
$tw.utils.each(this.attributes,function(attribute,name) {
if(name.charAt(0) !== "$") {
self.wiki.setText(self.actionTiddler,name,undefined,attribute,options);
}
});
return true; // Action was invoked
};
```
Best,
Joshua Fontany
…On Sat, Jun 12, 2021 at 5:04 AM seneschal2 ***@***.***> wrote:
Hi Folks,
Parse rule is working (parse tiddler/haystack for needles) and completing
with:
return [{
type: "action-setfield",
tag: "$action-setfield",
params: params
attributes: {
field : {type: "string", value: 'needles'},
value : {type: "string", value: needlesList}
},
children: parseResults.tree
}];
Not sure this rusty newb can create a custom widget, but expecting
action-setfield to work. (no joy)
The widget should have no impact on the tiddler other than parsing for
tiddler text and creating the "needles" field with list of the "needles".
Looking for recommendations. Thank you! This following-up on Trying to
keep my unique parse tree
<https://groups.google.com/g/tiddlywikidev/c/hTcrOaQ7b7I/m/fv-jCAedAQAJ>
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#5783>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACFOMB7ZE7VLC53Z4MWRQ23TSNENLANCNFSM46SVWQQA>
.
|
Beta Was this translation helpful? Give feedback.
-
actions are only activated by events. So it's not enough to see what the parser returns. .. The context is important too. |
Beta Was this translation helpful? Give feedback.
-
"actions are only activated by events" -- thanks Mario. How would I set a field value (create if necessary) based on the parser (wikiparser/rule)? Perhaps I return a custom fieldsWidget? What might that look like? Thanks for your patience. |
Beta Was this translation helpful? Give feedback.
-
@seneschal2 if I understand correctly, you have a custom parse rule that parses your tiddlers and generates a parse tree. You then have a macro that can render this parse tree. Normally, the parse tree indicates widgets that should be user to render the content. Parsers cannot and should not set field values. The best approach would be to create a custom widget that does exactly what your macro does. That is, accepts your parse tree as a parameter and renders it. Then in your parse tree you return that widget with the parse tree as its parameter. A shortcut here could be to return in your parser a macrocall widget which invokes your macro to render the content. The challenge would probably be in properly passing the parseTree as a string parameter. |
Beta Was this translation helpful? Give feedback.
-
Hi Folks,
Parse rule is working (parse tiddler/haystack for needles) and completing with:
return [{
type: "action-setfield",
tag: "$action-setfield",
attributes: {
field : {type: "string", value: 'needles'},
value : {type: "string", value: 'needlesList'}
},
children: parseResults.tree
}];
Not sure this rusty newb can create a custom widget, but expecting action-setfield to work. (new needles field with string value of "needlesList") (no joy)
The widget should have no impact on the tiddler other than parsing for tiddler text and creating the "needles" field with list of the "needles".
Looking for recommendations. Thank you! This following-up on Trying to keep my unique parse tree
Beta Was this translation helpful? Give feedback.
All reactions