Clint Checketts
unread,Oct 23, 2006, 12:03:43 AM10/23/06Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Tiddly...@googlegroups.com
I was just playing with the Edit Macro and came across a case where I wanted to have some fields have default values. I'm falling in love with the relatively old feature of Templates. I tweaked the Edit macro so I can do the following:
I wanted to put <span macro='edit myField "Some default"'></span> Its a very simple change (just one extra line of code) Does this interest anyone else? I like it so much that I think it would be a super addition to the core. I'm using it to set a tiddler's extended field to set the template that it will require for rendering in coordination with another plugin of course. (Like <span macro='edit ViewTemplate SpecialViewTemplate'></span>)
I've pasted the macro below to show how simple the change is. Changed lines are Bold:
-Clint
config.macros.edit.handler = function(place,macroName,params,wikifier,paramString,tiddler)
{
var field = params[0];
var defaultVal = params[1] ? params[1] : "";
if((tiddler instanceof Tiddler) && field)
{
story.setDirty(tiddler.title,true);
if(field != "text")
{
var e = createTiddlyElement(null,"input");
if(tiddler.isReadOnly())
e.setAttribute("readOnly","readOnly");
e.setAttribute("edit",field);
e.setAttribute("type","text");
var v = store.getValue
(tiddler,field);
if(!v)
v = defaultVal;
e.value = v;
e.setAttribute("size","40");
e.setAttribute("autocomplete","off");
place.appendChild(e);
}
else
{
var wrapper1 = createTiddlyElement(null,"fieldset",null,"fieldsetFix");
var wrapper2 = createTiddlyElement(wrapper1,"div");
var e = createTiddlyElement(wrapper2,"textarea");
if(tiddler.isReadOnly())
e.setAttribute("readOnly","readOnly");
var v = store.getValue(tiddler,field);
if(!v)
v = defaultVal;
e.value = v;
var rows = 10;
var lines = v.match(/\n/mg);
var maxLines = Math.max(parseInt(config.options.txtMaxEditRows),5);
if(lines != null &&
lines.length > rows)
rows = lines.length + 5;
rows = Math.min(rows,maxLines);
e.setAttribute("rows",rows);
e.setAttribute("edit",field);
place.appendChild(wrapper1);
}
}
}