Automatically adding tags when using NewTiddlerWithForm

21 views
Skip to first unread message

Nickname

unread,
Sep 7, 2007, 9:37:51 PM9/7/07
to TiddlyWiki
Hello,

I am using the FormTiddlerPlugin from abegoExtensions (http://
tiddlywiki.abego-software.de/). The item I'm looking for help on is
the NewTiddlerWithFormMacro.

I'm able to successfully use the NewTiddlerWithForm macro to create a
new form. However I was wondering if there was a way I could
automatically add a specific tag (or tags) to the newly created
tiddler.

Is this possible with this tool, or possibly using an additional
plugin?

Thanks

john

unread,
Sep 8, 2007, 1:20:31 PM9/8/07
to TiddlyWiki
The NewTiddlerWithFormMacro has a var tags statement in the code about
the 8th line from the bottom. You can add the tags in there if you
want. Since I have multiple forms, I duplicated the
NewTiddlerWithFormMacro for each form I use where I need custom tags
applied...just adjusting the tag statement near the bottom and of
course the macro and handler name.

There's likely a much better way to do this but this is how I am doing
it.

Here's and example:
Note edits on the lines near the top that begin with config.macros
(added 'SS' in ex below).
And edited line near bottom where var tags is.
//
============================================================================
// newTiddlerWithForm Macro
//
============================================================================

config.macros.newSSTiddlerWithForm = {
// Standard Properties
label: "newTiddlerWithForm",
version: {major: 1, minor: 0, revision: 1, date: new Date(2006, 1,
6)},
prompt: "Creates a new Tiddler with a <<formTiddler ...>> macro"
}

config.macros.newSSTiddlerWithForm.handler =
function(place,macroName,params) {
// --- Parsing ------------------------------------------

var i = 0; // index running over the params

// get the name of the form template tiddler
var formTemplateName = undefined;
if (i < params.length) {
formTemplateName = params[i];
i++;
}

if (!formTemplateName) {
config.macros.formTiddler.createErrorElement(place, "No form
template specified in <<" + macroName + ">>.");
return;
}

// get the button label
var buttonLabel = undefined;
if (i < params.length) {
buttonLabel = params[i];
i++;
}

if (!buttonLabel) {
config.macros.formTiddler.createErrorElement(place, "No button label
specified in <<" + macroName + ">>.");
return;
}

// get the (optional) tiddlerName script and "askUser"
var tiddlerNameScript = undefined;
var askUser = false;
if (i < params.length) {
tiddlerNameScript = params[i];
i++;

if (i < params.length && params[i] == "askUser") {
askUser = true;
i++;
}
}

// --- Processing ------------------------------------------

if(!readOnly) {
var onClick = function() {
var tiddlerName;
if (tiddlerNameScript) {
try {
tiddlerName = eval(tiddlerNameScript);
} catch (ex) {
}
}
if (!tiddlerName || askUser) {
tiddlerName = prompt("Please specify a tiddler name.", askUser ?
tiddlerName : "");
}
while (tiddlerName && store.getTiddler(tiddlerName)) {
tiddlerName = prompt("A tiddler named '"+tiddlerName+"' already
exists.\n\n"+"Please specify a tiddler name.", tiddlerName);
}

// tiddlerName is either null (user canceled) or a name that is not
yet in the store.
if (tiddlerName) {
var body = "<<formTiddler [["+formTemplateName+"]]>>";
var tags = ["socialsecurity", "Encrypt(PrivateData)"];

store.saveTiddler(tiddlerName,tiddlerName,body,config.options.txtUserName,new
Date(),tags);
story.displayTiddler(null,tiddlerName,1);
}
}

createTiddlyButton(place,buttonLabel,buttonLabel,onClick);
}
}


On Sep 7, 9:37 pm, Nickname <stillnotbl...@excessivemasturbation.com>
wrote:

Reply all
Reply to author
Forward
0 new messages