From 6b3fc8d5381a20925086c4b2a6c7101f9deb409a Mon Sep 17 00:00:00 2001 From: Tobias Beer Date: Fri, 25 Sep 2015 15:20:37 +0200 Subject: [PATCH 1/2] updated #1480 "undefined value removes field or index" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit when $value is unspecified, $action-setfield removes field or index... modified setText() — $:/core/modules/wiki.js invokeAction() — $:/core/modules/widgets/action-setfield demo http://tobibeer.github.io/tw/batch/#ActionSetField-RemoveIndex --- core/modules/widgets/action-setfield.js | 4 +--- core/modules/wiki.js | 6 +++++- editions/tw5.com/tiddlers/widgets/ActionSetFieldWidget.tid | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/core/modules/widgets/action-setfield.js b/core/modules/widgets/action-setfield.js index 5f40d4e3c..1e1ba6d8e 100644 --- a/core/modules/widgets/action-setfield.js +++ b/core/modules/widgets/action-setfield.js @@ -61,9 +61,7 @@ SetFieldWidget.prototype.invokeAction = function(triggeringWidget,event) { var self = this, options = {}; options.suppressTimestamp = !this.actionTimestamp; - if(typeof this.actionValue === "string") { - this.wiki.setText(this.actionTiddler,this.actionField,this.actionIndex,this.actionValue,options); - } + this.wiki.setText(this.actionTiddler,this.actionField,this.actionIndex,this.actionValue,options); $tw.utils.each(this.attributes,function(attribute,name) { if(name.charAt(0) !== "$") { self.wiki.setText(self.actionTiddler,name,undefined,attribute,options); diff --git a/core/modules/wiki.js b/core/modules/wiki.js index 9e6a30383..b6e9fa068 100755 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -65,7 +65,11 @@ exports.setText = function(title,field,index,value,options) { // Check if it is a reference to a tiddler field if(index) { var data = this.getTiddlerData(title,Object.create(null)); - data[index] = value; + if(value !== undefined) { + data[index] = value; + } else { + delete data[index]; + } this.setTiddlerData(title,data,modificationFields); } else { var tiddler = this.getTiddler(title), diff --git a/editions/tw5.com/tiddlers/widgets/ActionSetFieldWidget.tid b/editions/tw5.com/tiddlers/widgets/ActionSetFieldWidget.tid index 3656accfc..dcfb086d7 100644 --- a/editions/tw5.com/tiddlers/widgets/ActionSetFieldWidget.tid +++ b/editions/tw5.com/tiddlers/widgets/ActionSetFieldWidget.tid @@ -17,7 +17,7 @@ The ''action-setfield'' widget is invisible. Any content within it is ignored. |$tiddler |The title of the tiddler whose fields are to be modified (if not provided defaults to the [[current tiddler|Current Tiddler]] | |$field |Optional name of a field to be assigned the $value attribute | |$index |Optional index of a property in a [[data tiddler|DataTiddlers]] to be assigned the $value attribute| -|$value |The value to be assigned to the field or index identified by the $field or $index attribute. If neither is specified then the value is assigned to the text field | +|$value |The value to be assigned to the field or index identified by the $field or $index attribute. If neither is specified then the value is assigned to the text field. If no value is specified, $field or $index are being deleted.| |$timestamp |Specifies whether the timestamp(s) of the target tiddler will be updated (''modified'' and ''modifier'', plus ''created'' and ''creator'' for newly created tiddlers). Can be "yes" (the default) or "no" | |//{any attributes not starting with $}// |Each attribute name specifies a field to be modified with the attribute value providing the value to assign to the field | From 1b2d54b4bf503aa9323a6a57311350a289d91d74 Mon Sep 17 00:00:00 2001 From: Tobias Beer Date: Fri, 25 Sep 2015 15:43:31 +0200 Subject: [PATCH 2/2] wording for docs --- editions/tw5.com/tiddlers/widgets/ActionSetFieldWidget.tid | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/editions/tw5.com/tiddlers/widgets/ActionSetFieldWidget.tid b/editions/tw5.com/tiddlers/widgets/ActionSetFieldWidget.tid index dcfb086d7..0e46808f7 100644 --- a/editions/tw5.com/tiddlers/widgets/ActionSetFieldWidget.tid +++ b/editions/tw5.com/tiddlers/widgets/ActionSetFieldWidget.tid @@ -17,7 +17,7 @@ The ''action-setfield'' widget is invisible. Any content within it is ignored. |$tiddler |The title of the tiddler whose fields are to be modified (if not provided defaults to the [[current tiddler|Current Tiddler]] | |$field |Optional name of a field to be assigned the $value attribute | |$index |Optional index of a property in a [[data tiddler|DataTiddlers]] to be assigned the $value attribute| -|$value |The value to be assigned to the field or index identified by the $field or $index attribute. If neither is specified then the value is assigned to the text field. If no value is specified, $field or $index are being deleted.| +|$value |The value to be assigned to the field or index identified by the $field or $index attribute. If neither is specified then the value is assigned to the text field. If no value is specified, $field or $index will be deleted.| |$timestamp |Specifies whether the timestamp(s) of the target tiddler will be updated (''modified'' and ''modifier'', plus ''created'' and ''creator'' for newly created tiddlers). Can be "yes" (the default) or "no" | |//{any attributes not starting with $}// |Each attribute name specifies a field to be modified with the attribute value providing the value to assign to the field |