[TWC] Input Box for creating new tiddlers

44 views
Skip to first unread message

jpt

unread,
May 4, 2015, 6:15:47 AM5/4/15
to tiddl...@googlegroups.com
Hi,
Modifying the "Note" tiddler by Tobias Beer (http://lastfm.tiddlyspot.com/#Notes) I was able to use the following code as a transclusion (<<tiddler inputBox with:"tag tag tag">>). 
It allows for the "silent" creation of tiddlers by entering their title into the box and pressing enter. 
I have not been able to make it so that the focus returns to the input box, but then my use of the AutoRefresh tranclusion might have messed with that.
It's called "inputBox" and here is the code:
<html><nowiki>
    <form id="Notes" style="width:100%;height:20px;">
        <input 
            title="message title" 
            name="msgTitle" 
            type="text" 
            cols="60" 
            style="
                width:100%;
                height:20px;
                padding:0px;
                margin-bottom:1px;
                margin-right:2px;
                border:1px solid #CCC;" 
            onKeydown="
if (event.keyCode == 13){
var note=this.form.msgBody.value;
var tags=this.form.msgTags.value.readBracketedList();
tags.push();
var tid = store.getTiddler('tiddler');
var who=config.options.txtUserName; 
var when=new Date();
var title=this.form.msgTitle.value;
if (title=='') title=when.formatString('YYYY-0MM-0DD 0hh:0mm:0ss');
var msg=config.messages.overwriteWarning.format([title]);
if (store.tiddlerExists(title) && !confirm(msg)) return; 
store.saveTiddler(title,title,note,who,when,tags,{}); 
refreshDisplay('$2');
story.refreshTiddler('$3',null,true);
this.form.msgTitle.value='';
this.form.msgTags.value='';
this.form.msgBody.value='';
this.form.msgTitle.focus();}">
        <input 
            title="tags added to message" 
            name="msgTags" 
            type="text" 
            value="$1" 
            cols="60" 
            style="display:none;">
        <textarea 
            title="message body" 
            name="msgBody" 
            value="$4" 
            rows="1" 
            cols="0" 
            style="display:none;">
        </textarea>
    </form>
</html>
Note the use of the place holders $1, $2, $3, $4. 
Any suggestions for improvements are welcome.

Regards,
Johannes

Reply all
Reply to author
Forward
0 new messages