Edit Macro Enhancement idea: Default Values

7 views
Skip to first unread message

Clint Checketts

unread,
Oct 23, 2006, 12:03:43 AM10/23/06
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);
            }
        }
}

Simon Baird

unread,
Oct 23, 2006, 1:27:45 AM10/23/06
to Tiddly...@googlegroups.com
I like it.


On 10/23/06, Clint Checketts <chec...@gmail.com> wrote:
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



--
Simon Baird <simon...@gmail.com>

Udo Borkowski

unread,
Oct 25, 2006, 4:21:47 AM10/25/06
to Tiddly...@googlegroups.com
Hi Clint,

nice idea. I added a ticket to cover this enhancement: http://trac.tiddlywiki.org/tiddlywiki/ticket/215

Udo

----------
Udo Borkowski
http://www.abego-software.de



On 10/23/06, Clint Checketts < chec...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages