1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-25 23:03:15 +00:00

Extended edit macro

Now it accepts a default value for the field if the tiddler doesn't
exist. It also allows the forcing of a single line input control
This commit is contained in:
Jeremy Ruston 2012-07-13 13:02:14 +01:00
parent 6e86de5652
commit 36ff53f40b
2 changed files with 22 additions and 16 deletions

View File

@ -16,7 +16,9 @@ exports.info = {
name: "edit",
params: {
field: {byPos: 0, type: "text"},
tiddler: {byName: true, type: "tiddler"}
tiddler: {byName: true, type: "tiddler"},
singleline: {byName: true, type: "text"},
"default": {byName: true, type: "text"}
}
};

View File

@ -30,16 +30,20 @@ TextEditor.prototype.getEditText = function() {
value = tiddler.getFieldString(this.macroNode.editField);
} else {
// Otherwise, we need to construct a default value for the editor
switch(this.macroNode.editField) {
case "text":
value = "Type the text for the tiddler '" + this.macroNode.editTiddler + "'";
break;
case "title":
value = this.macroNode.editTiddler;
break;
default:
value = "";
break;
if(this.macroNode.hasParameter("default")) {
value = this.macroNode.params["default"];
} else {
switch(this.macroNode.editField) {
case "text":
value = "Type the text for the tiddler '" + this.macroNode.editTiddler + "'";
break;
case "title":
value = this.macroNode.editTiddler;
break;
default:
value = "";
break;
}
}
}
return {tiddler: tiddler, field: this.macroNode.editField, value: value};
@ -53,16 +57,16 @@ TextEditor.prototype.getChild = function() {
tagName,
content = [];
// Make a textarea for text fields and an input box for other fields
if(edit.field === "text") {
tagName = "textarea";
content.push($tw.Tree.Text(edit.value));
} else {
if(edit.field !== "text" || this.macroNode.hasParameter("singleline")) {
tagName = "input";
attributes.type = "text";
attributes.value = edit.value;
} else {
tagName = "textarea";
content.push($tw.Tree.Text(edit.value));
}
// Wrap the editor control in a div
return $tw.Tree.Element("div",{},[$tw.Tree.Element(tagName,attributes,content)],{
return $tw.Tree.Element(this.macroNode.isBlock ? "div" : "span",{},[$tw.Tree.Element(tagName,attributes,content)],{
events: ["focus","keyup"],
eventHandler: this
});