1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-27 20:10:03 +00:00

Revert to using fieldmangler for adding fields

In 5.1.5 we switched to using `<$action-setfield>` instead of
`<$fieldmangler>`. The problem was that in the process we lost the
validation of field names, making it possible to create fields with
illegal names

Fixes #1186
This commit is contained in:
Jermolene 2014-12-04 09:39:14 +00:00
parent bb74be7ac1
commit 2689e2861b
2 changed files with 51 additions and 21 deletions

View File

@ -71,24 +71,38 @@ FieldManglerWidget.prototype.handleRemoveFieldEvent = function(event) {
}; };
FieldManglerWidget.prototype.handleAddFieldEvent = function(event) { FieldManglerWidget.prototype.handleAddFieldEvent = function(event) {
var tiddler = this.wiki.getTiddler(this.mangleTitle); var tiddler = this.wiki.getTiddler(this.mangleTitle),
if(tiddler && typeof event.param === "string") { addition = this.wiki.getModificationFields(),
var name = event.param.toLowerCase().trim(); hadInvalidFieldName = false,
if(name !== "" && !$tw.utils.hop(tiddler.fields,name)) { addField = function(name,value) {
if(!$tw.utils.isValidFieldName(name)) { var trimmedName = name.toLowerCase().trim();
debugger;
if(!$tw.utils.isValidFieldName(trimmedName)) {
if(!hadInvalidFieldName) {
alert($tw.language.getString( alert($tw.language.getString(
"InvalidFieldName", "InvalidFieldName",
{variables: {variables:
{fieldName: name} {fieldName: trimmedName}
} }
)); ));
return true; hadInvalidFieldName = true;
return;
}
} else {
addition[trimmedName] = value || "";
}
return;
};
addition.title = this.mangleTitle;
if(typeof event.param === "string") {
addField(event.param,"");
}
if(typeof event.paramObject === "object") {
for(var name in event.paramObject) {
addField(name,event.paramObject[name]);
}
} }
var addition = this.wiki.getModificationFields();
addition[name] = "";
this.wiki.addTiddler(new $tw.Tiddler(tiddler,addition)); this.wiki.addTiddler(new $tw.Tiddler(tiddler,addition));
}
}
return true; return true;
}; };

View File

@ -5,9 +5,27 @@ tags: $:/tags/EditTemplate
\define config-title() \define config-title()
$:/config/EditTemplateFields/Visibility/$(currentField)$ $:/config/EditTemplateFields/Visibility/$(currentField)$
\end \end
\define config-filter() \define config-filter()
[[hide]] -[title{$(config-title)$}] [[hide]] -[title{$(config-title)$}]
\end \end
\define new-field(name,value)
<$reveal type="nomatch" text="" default="""$name$""">
<$button>
<$action-sendmessage $message="tm-add-field" $name$="""$value$"""/>
<$action-deletetiddler $tiddler="$:/temp/newfieldname"/>
<$action-deletetiddler $tiddler="$:/temp/newfieldvalue"/>
<<lingo Fields/Add/Button>>
</$button>
</$reveal>
<$reveal type="match" text="" default="""$name$""">
<$button>
<<lingo Fields/Add/Button>>
</$button>
</$reveal>
\end
<div class="tc-edit-fields"> <div class="tc-edit-fields">
<table class="tc-edit-fields"> <table class="tc-edit-fields">
<tbody> <tbody>
@ -32,6 +50,7 @@ $:/config/EditTemplateFields/Visibility/$(currentField)$
</table> </table>
</div> </div>
<$fieldmangler>
<div class="tc-edit-field-add"> <div class="tc-edit-field-add">
<em class="tc-edit"> <em class="tc-edit">
<<lingo Fields/Add/Prompt>> <<lingo Fields/Add/Prompt>>
@ -43,11 +62,8 @@ $:/config/EditTemplateFields/Visibility/$(currentField)$
<$edit-text tiddler="$:/temp/newfieldvalue" tag="input" default="" placeholder={{$:/language/EditTemplate/Fields/Add/Value/Placeholder}} class="tc-edit-texteditor"/> <$edit-text tiddler="$:/temp/newfieldvalue" tag="input" default="" placeholder={{$:/language/EditTemplate/Fields/Add/Value/Placeholder}} class="tc-edit-texteditor"/>
</span> </span>
<span class="tc-edit-field-add-button"> <span class="tc-edit-field-add-button">
<$button> <$macrocall $name="new-field" name={{$:/temp/newfieldname}} value={{$:/temp/newfieldvalue}}/>
<$action-setfield $field={{$:/temp/newfieldname}} $value={{$:/temp/newfieldvalue}}/>
<$action-deletetiddler $tiddler="$:/temp/newfieldname"/>
<$action-deletetiddler $tiddler="$:/temp/newfieldvalue"/>
<<lingo Fields/Add/Button>>
</$button>
</span> </span>
</div> </div>
</$fieldmangler>