1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-26 19:47:20 +00:00

Trim spaces from new field and tag names

Fixes #517
This commit is contained in:
Jermolene 2014-03-31 17:59:28 +01:00
parent 6307293469
commit c3e24c1228

View File

@ -74,7 +74,7 @@ FieldManglerWidget.prototype.handleAddFieldEvent = function(event) {
var tiddler = this.wiki.getTiddler(this.mangleTitle), var tiddler = this.wiki.getTiddler(this.mangleTitle),
fieldValidatorRegEx = /^[a-z\-\._]+$/mg; fieldValidatorRegEx = /^[a-z\-\._]+$/mg;
if(tiddler && typeof event.param === "string") { if(tiddler && typeof event.param === "string") {
var name = event.param.toLowerCase(); var name = event.param.toLowerCase().trim();
if(name !== "" && !$tw.utils.hop(tiddler.fields,name)) { if(name !== "" && !$tw.utils.hop(tiddler.fields,name)) {
if(!fieldValidatorRegEx.test(name)) { if(!fieldValidatorRegEx.test(name)) {
alert($tw.language.getString( alert($tw.language.getString(
@ -112,11 +112,14 @@ FieldManglerWidget.prototype.handleRemoveTagEvent = function(event) {
FieldManglerWidget.prototype.handleAddTagEvent = function(event) { FieldManglerWidget.prototype.handleAddTagEvent = function(event) {
var tiddler = this.wiki.getTiddler(this.mangleTitle); var tiddler = this.wiki.getTiddler(this.mangleTitle);
if(tiddler && typeof event.param === "string" && event.param !== "") { if(tiddler && typeof event.param === "string") {
var modification = this.wiki.getModificationFields(); var tag = event.param.trim();
modification.tags = (tiddler.fields.tags || []).slice(0); if(tag !== "") {
$tw.utils.pushTop(modification.tags,event.param); var modification = this.wiki.getModificationFields();
this.wiki.addTiddler(new $tw.Tiddler(tiddler,modification)); modification.tags = (tiddler.fields.tags || []).slice(0);
$tw.utils.pushTop(modification.tags,tag);
this.wiki.addTiddler(new $tw.Tiddler(tiddler,modification));
}
} }
return true; return true;
}; };