A question regarding tiddlytools.com CheckboxPlugin

37 views
Skip to first unread message

Kashgarinn

unread,
Jan 2, 2008, 4:35:24 AM1/2/08
to TiddlyWiki
Hi there, hope it's ok if I ask this question here.

I'm using the checkboxplugin from tiddlytools.com to create a
checklist for the nightshift at my workplace.

I'm using this in a CCtiddlywiki instead of a normal tiddlywiki, and
that means the autosaving feature doesn't work.

The final checkmark should tag the tiddler "done" and then also "save"
the tiddler to the server, I know that the macro for uploading the
store area is <<ssUploadStoreArea>>, I was wondering if I could let
the checkmark tag the tiddler "done" as well as make it run that
particular macro when checked?

I don't see if that's possible.. but I'm hoping I'm missing something.

K.

Eric Shulman

unread,
Jan 2, 2008, 7:35:06 AM1/2/08
to TiddlyWiki
> I'm using the checkboxplugin from tiddlytools.com to create a
> checklist for the nightshift at my workplace.
> I'm using this in a CCtiddlywiki instead of a normal tiddlywiki, and
> that means the autosaving feature doesn't work.
> The final checkmark should tag the tiddler "done" and then also "save"
> the tiddler to the server, I know that the macro for uploading the
> store area is <<ssUploadStoreArea>>, I was wondering if I could let
> the checkmark tag the tiddler "done" as well as make it run that
> particular macro when checked?

You can include "side effect" handlers in a checkbox to invoke
javascript code:

[x(done){init handler}{beforeclick handler}{afterclick handler}]

For example, using the core's standard "saveChanges()" function:

[x(done){}{}{if (saveChanges()}]

with this syntax, each time you click the checkbox, after the plugin
sets the checkbox's current state (and the corresponding "done" tag),
saveChanges() is automatically invoked. Note that in this example
there are no "init" or "beforeclick" handlers, so they are entered
using "{}" as placeholders.

IMPORTANT NOTE: To use an "afterclick" custom handler in a checkbox,
you need to install the most recent update (v 2.3.0)
http://www.TiddlyTools.com/#CheckboxPlugin

As to your specific use-case:

For CCTiddly, I don't think you can just invoke saveChanges()... but,
as you noted, there is a macro <<ssUploadStoreArea>> that does the
desired action (i.e.,saving to the server).

IF you can identify an programmatic entry point into that macro that
can be invoked directly from javascript, then you can trigger it from
a checkbox, using the above technique.

HTH,
-e
Eric Shulman
TiddlyTools / ELS Design Studios

Kashgarinn

unread,
Jan 3, 2008, 11:00:18 AM1/3/08
to TiddlyWiki
hmm, I got this responce from coolcold:

"The uploadStoreArea function uploads all your tiddlers to the server
and is
not recommended for checkboxplugin. i would recommend to call the
saveTiddler function instead when the check box is ticked."

- so trying the saveTiddler function like this: [_(|Búið){}{}
{saveTiddler()}]

gave me the error: Checkbox onClickAfter error: ReferenceError:
saveTiddler is not defined

- Am I using the function wrong?

K.

FND

unread,
Jan 4, 2008, 3:34:37 AM1/4/08
to Tiddl...@googlegroups.com
> trying the saveTiddler function like this: [_(|Búið){}{}
> {saveTiddler()}]
> gave me the error

You'd use the saveTiddler() function like this:
store.saveTiddler(currentTitle, newTitle, text, modifier, modified,
tags, fields, clearChangeCount, created)

Not entirely sure how that would work in this context though (i.e. where
to get the parameters values from) - Eric can probably answer that.


-- F.

Kashgarinn

unread,
Jan 4, 2008, 5:56:06 AM1/4/08
to TiddlyWiki
Hmm, that's interesting.

I tried this :

[_(Búið){}{}{store.saveTiddler(tiddler.title, tiddler.title,
tiddler.text, tiddler.modifier, tiddler.modified, tiddler.tags,
tiddler.fields)}]

for the checkbox, and now it says "tiddler saved" in the yellow alert
window - but it doesn't save it really..

am I using the function wrong?

K.

Kashgarinn

unread,
Jan 4, 2008, 6:22:31 AM1/4/08
to TiddlyWiki
I was checking the wiki with firebug, and I think I was saving the
"yoursearchplugin" tiddler, which is probably the last tiddler being
processed from loading the wiki itself.. so I probably need to locate
the tiddler the checkmark is in.. which I have no idea how to do..
trying to google it and browsing through firebug :P

K.

FND

unread,
Jan 5, 2008, 2:33:21 AM1/5/08
to Tiddl...@googlegroups.com
> I probably need to locate
> the tiddler the checkmark is in.. which I have no idea how to do..

Yeah - that might become tricky though. Could you send me a simple TW
document (directly to my address, zipped if possible) with the
CheckboxPlugin and your custom code? I'll take a look, but no promises...


-- F.

Eric Shulman

unread,
Jan 5, 2008, 9:34:38 AM1/5/08
to TiddlyWiki
> I was checking the wiki with firebug, and I think I was saving the
> "yoursearchplugin" tiddler, which is probably the last tiddler being
> processed from loading the wiki itself.. so I probably need to locate
> the tiddler the checkmark is in.. which I have no idea how to do..

I've just UPDATED (to v2.4.0)
http://www.TiddlyTools.com/#CheckboxPlugin
so that, whenever a checkbox is clicked, it automatically defines a
global variable, "place" (actually, "window.place") that refers to the
checkbox DOM element itself.

Similar to the use of 'place' InlineJavascriptPlugin (and in macro
definitions), this variable can be used within the checkbox init/
beforeClick/afterClick handlers to do all sorts of DOM-related
functions, including story.findContainingTiddler()...

Thusly:

[x(done){}{}{
var id=story.findContainingTiddler(place).getAttribute("tiddler");
displayMessage("in "+id+", state="+place.checked)
}] test this

and for your purposes:

[x(done){}{}{
if (!place.checked) return; // only if 'done' is checked...
var
tid=store.getTiddler(story.findContainingTiddler(place).getAttribute("tiddler"));
store.saveTiddler(tid.title, tid.title, tid.text, tid.modifier,
tid.modified, tid.tags, tid.fields)
}] DONE (with save)

After you install the updated CheckboxPlugin, you should be all set...

enjoy,
-e

Kashgarinn

unread,
Jan 7, 2008, 4:38:54 AM1/7/08
to TiddlyWiki
Hi there, It works :D but at first it didn't work, here's the story:

I tried your suggestion, but I got an error in the new journal macro
when trying to create it there...

1. Error while executing macro <<newJournal>>:
2. Unable to evaluate {{"<<tiddler [[Kvöldferlið]]>\>" + " [x(done){}{}
{var
tid=store.getTiddler(story.findContainingTiddler(place).getAttribute("tiddler"));}]
Allt ferlið lokið?"}}: SyntaxError: missing ; before statement

It worked when I had just the if statement, but if I had just the var
tid statement, then it didn't work..
I tried doing just :{var tid = 'testing';} - and that worked.

Here's the whole new journal macro:

<<newJournal
"DD MMM YYYY"
label:"nýtt Kvöldferli"
prompt:"create a new nightshift tiddler"
text:{{"<<tiddler [[Kvöldferlið]]>\>" + " [x(done){}{}{if (!
place.checked) return; var
tid=store.getTiddler(story.findContainingTiddler(place).getAttribute("tiddler"));
store.saveTiddler(tid.title, tid.title, tid.text, tid.modifier,
tid.modified, tid.tags, tid.fields);}] Allt ferlið lokið?"}}
tag:"Kvöldferli"
>>

You know what the problem was? the "" marks.. I tried changing it to '
' and then it worked :D

Thanks for your help btw, this is a very nice feature :)

K.

Eric Shulman

unread,
Jan 7, 2008, 5:56:41 AM1/7/08
to TiddlyWiki
> Hi there, It works :D but at first it didn't work, here's the story:
> You know what the problem was? the "" marks.. I tried changing it to '
> ' and then it worked :D

Nested quotes in macro parameter syntax is a notorious problem... ask
anyone who has tried to write a <<forEachTiddler>> macro!

The checkbox syntax example I provided used double-quotes.... which is
normally OK. However, in this particular case, the checkbox syntax is
already contained inside double-quotes, as part of the 'computed
parameter' value for the macro. Thus, the code inside the checkbox's
afterClick handler can't also use the double-quotes (as you
discovered). Fortunately, it *can* use the single quotes... in this
case.

However... there are other limitations on what kind of javascript code
you an put directly inside the checkbox handlers... for example, you
can't use curly-braces (e.g., {...}) to create an if-then-else
conditional or a simple "while" loop! In general, for anything more
complex than what you are doing, the checkbox handler code should
simply invoke externally defined functions. For example:

[x(done){myInit(this)}{myBeforeClick(this)}{myAfterClick(this)}]

where myInit(), myBeforeClick(), and myAfterClick() could be defined
in a separate plugin (e.g., [[CheckboxPluginHandlers]]), or using
InlineJavascriptPlugin to embed the handler function definitions
inline in the same tiddler as the checkbox itself.

HTH,
-e
Reply all
Reply to author
Forward
0 new messages