Once again I’m trying to do something above my pay grade: I’m customizing Projectify and I would like to use the pikaday widget in such a way that when the user selects a date these two things happen:
the date is stored in a specific field (already done)
a predefined TW macro is called.
My question is about the second point: how can I call a TW macro from a JS widget? (if that’s even possible?)
The current code for storing the date is like this (from here):
AbstractDatePickerWidget.prototype.setValue = function (date) {
let updateFields = {
title: this.title,
[this.field]: date ? this.formatDate(date) : undefined
};
this.wiki.addTiddler(
new $tw.Tiddler(
this.wiki.getCreationFields(),
this.getTiddler(),
updateFields,
this.wiki.getModificationFields()
)
);
$tw.rootWidget.dispatchEvent({type: "tm-auto-save-wiki"});
};
I want to have some quite complex wikitext code my-macro (set some field, create a tiddler if condition is satisfied, …) to execute when the user performs specific actions. There are at least two different scenarios where mymacro should be called: 1) the user clicks a button 2) the user selects a date using the pikaday widget.
So in case 2), I would like to call <<my-macro>> from the JS code.
If this is not possible, I can have the user first select the date and then click another button to trigger the macro. Of course it’s not as good, because then the user would need to do two actions instead of one.
@erwan I am glad you found your answer. I too have modified and enhanced projectify substantially. Your workaround here highlights the date picker issues we find in tiddlywiki, mostly because we dont have an established solution.
I will just let you know I and others have found or written date picker solutions. Eg tiddlytools so its worth some search and research