mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 18:17:20 +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:
parent
bb74be7ac1
commit
2689e2861b
@ -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();
|
||||||
alert($tw.language.getString(
|
debugger;
|
||||||
"InvalidFieldName",
|
if(!$tw.utils.isValidFieldName(trimmedName)) {
|
||||||
{variables:
|
if(!hadInvalidFieldName) {
|
||||||
{fieldName: name}
|
alert($tw.language.getString(
|
||||||
}
|
"InvalidFieldName",
|
||||||
));
|
{variables:
|
||||||
return true;
|
{fieldName: trimmedName}
|
||||||
|
}
|
||||||
|
));
|
||||||
|
hadInvalidFieldName = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
addition[trimmedName] = value || "";
|
||||||
}
|
}
|
||||||
var addition = this.wiki.getModificationFields();
|
return;
|
||||||
addition[name] = "";
|
};
|
||||||
this.wiki.addTiddler(new $tw.Tiddler(tiddler,addition));
|
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]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.wiki.addTiddler(new $tw.Tiddler(tiddler,addition));
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user