Macrobutton with fieldvaluechooser prompt - is it doable??

19 views
Skip to first unread message

Måns

unread,
Apr 9, 2009, 4:15:21 PM4/9/09
to TiddlyWiki
Hi I have 2 questions in this context..
1)
I' like to make a macrobutton which will ask for a value for a
predefined fieldname.
My button looks like this(without any specified fieldname yet):
<<newTiddler title: 'Name of class' tag: 'Class' label: 'New class |'
text: {{store.getTiddlerText("ClassSliderFrame")}}>>

Could I predefine a fieldname: teacher - and prompt for a value??

The user pushes the button and is asked to write the teachers initials
(fieldvalue) -
2)
The tiddler is created - and there isn't really any reason why it
should open in editmode - because it's already filled with a template
provided by the ClassViewTemplate... Can it just proceed to viewmode -
at once??

YS Måns Mårtensson

Eric Shulman

unread,
Apr 9, 2009, 5:14:57 PM4/9/09
to TiddlyWiki
> I' like to make a macrobutton which will ask for a value for a
> predefined fieldname.
> My button looks like this(without any specified fieldname yet):
> <<newTiddler title: 'Name of class' tag: 'Class' label: 'New class |'
> text: {{store.getTiddlerText("ClassSliderFrame")}}>>
>
> Could I predefine a fieldname: teacher - and prompt for a value??
> The user pushes the button and is asked to write the teachers initials
> (fieldvalue) -

The <<newTiddler>> parameter syntax for setting a field value is:
field:"name:'value'"
(note use of both single and double quotes)
Thus:
field:"teacher:'MM'"
To prompt for a value instead of using a fixed constant (e.g, "MM"),
you could use a computed parameter to automatically invoke a prompt()
dialog box to ask for the teachers initials, like this:
field:{{"teacher:'"+prompt("Enter teacher's initials","")+"'"}}

However... there's one catch: the <<newTiddler>> macro's computed
parameter will be evaluated (and the dialog box will be presented)
when the the "new class" command link is initially *rendered*, while
what you need is for the dialog box to be invoked each time you
*click* on the command link.

Fortunately, I have a solution:
http://www.TiddlyTools.com/#ClickifyPlugin
After installing, just write:
<<clickify newTiddler ... field:{{...}}>>
The additional 'clickify' keyword at the beginning of the macro will
cause any computed parameters to be invoked 'on click' instead of 'on
render', giving exactly the sequence you are after (i.e., click
command, display dialog, input initials, press OK, create tiddler)

> 2)
> The tiddler is created - and there isn't really any reason why it
> should open in editmode - because it's already filled with a template
> provided by the ClassViewTemplate... Can it just proceed to viewmode -
> at once??

Actually, this is even simpler than the above... by using
InlineJavscriptPlugin, you can write a custom 'onclick' command that
performs *any* scripted action you want, including creating new
tiddlers from prompted values and showing them... like this:

<script label="new class" title="create a new class">
var tid=prompt("Enter name of class","");
if (!tid || !tid.length) return;
var txt=store.getTiddlerText("ClassSliderFrame");
var who=config.options.txtUserName;
var when=new Date();
var tags=['Class'];
var initials=prompt("Enter teacher's initials","");
if (!initials || !initials.length) return;
var fields={ teacher: initials };
store.saveTiddler(tid,tid,txt,who,when,tags,fields);
story.displayTiddler(null,tid);
</script>

enjoy,
-e
Eric Shulman
TiddlyTools / ELS Design Studios

Måns

unread,
Apr 9, 2009, 5:40:22 PM4/9/09
to TiddlyWiki
Hi Eric

Some day - when I have the the time/loose my job as a teacher - I will
collect your answers into a TW titled
MagicalShulmanQuotes4all2enjoy...
Thank you very much!!

YS Måns Mårtensson
Reply all
Reply to author
Forward
0 new messages