From bfbd886a8bbf2f6ce147ea526eec2098357d3ae7 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Mon, 4 Nov 2019 18:56:22 +0000 Subject: [PATCH] Add "index" attribute to range widget --- core/modules/widgets/range.js | 21 +++++++++++++------ .../tw5.com/tiddlers/widgets/RangeWidget.tid | 13 ++++++------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/core/modules/widgets/range.js b/core/modules/widgets/range.js index eee536487..d5ab2c785 100644 --- a/core/modules/widgets/range.js +++ b/core/modules/widgets/range.js @@ -61,10 +61,14 @@ RangeWidget.prototype.getValue = function() { fieldName = this.tiddlerField || "text", value = this.defaultValue; if(tiddler) { - if($tw.utils.hop(tiddler.fields,fieldName)) { - value = tiddler.fields[fieldName] || ""; + if(this.tiddlerIndex) { + value = this.wiki.extractTiddlerDataItem(tiddler,this.tiddlerIndex,this.defaultValue || ""); } else { - value = this.defaultValue || ""; + if($tw.utils.hop(tiddler.fields,fieldName)) { + value = tiddler.fields[fieldName] || ""; + } else { + value = this.defaultValue || ""; + } } } return value; @@ -72,7 +76,11 @@ RangeWidget.prototype.getValue = function() { RangeWidget.prototype.handleInputEvent = function(event) { if(this.getValue() !== this.inputDomNode.value) { - this.wiki.setText(this.tiddlerTitle,this.tiddlerField,null,this.inputDomNode.value); + if(this.tiddlerIndex) { + this.wiki.setText(this.tiddlerTitle,"",this.tiddlerIndex,this.inputDomNode.value); + } else { + this.wiki.setText(this.tiddlerTitle,this.tiddlerField,null,this.inputDomNode.value); + } } }; @@ -83,6 +91,7 @@ RangeWidget.prototype.execute = function() { // Get the parameters from the attributes this.tiddlerTitle = this.getAttribute("tiddler",this.getVariable("currentTiddler")); this.tiddlerField = this.getAttribute("field"); + this.tiddlerIndex = this.getAttribute("index"); this.minValue = this.getAttribute("min"); this.maxValue = this.getAttribute("max"); this.increment = this.getAttribute("increment"); @@ -97,7 +106,7 @@ Selectively refreshes the widget if needed. Returns true if the widget or any of */ RangeWidget.prototype.refresh = function(changedTiddlers) { var changedAttributes = this.computeAttributes(); - if(changedAttributes.tiddler || changedAttributes.field || changedAttributes['min'] || changedAttributes['max'] || changedAttributes['increment'] || changedAttributes["default"] || changedAttributes["class"]) { + if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.index || changedAttributes['min'] || changedAttributes['max'] || changedAttributes['increment'] || changedAttributes["default"] || changedAttributes["class"]) { this.refreshSelf(); return true; } else { @@ -115,4 +124,4 @@ RangeWidget.prototype.refresh = function(changedTiddlers) { exports.range = RangeWidget; -})(); +})(); \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/widgets/RangeWidget.tid b/editions/tw5.com/tiddlers/widgets/RangeWidget.tid index dcb793f29..8449449e5 100644 --- a/editions/tw5.com/tiddlers/widgets/RangeWidget.tid +++ b/editions/tw5.com/tiddlers/widgets/RangeWidget.tid @@ -1,6 +1,6 @@ caption: range created: 20171102134825376 -modified: 20180425132848231 +modified: 20191104185454972 tags: Widgets title: RangeWidget type: text/vnd.tiddlywiki @@ -15,11 +15,12 @@ The content of the `<$range>` widget is ignored. |!Attribute |!Description | |tiddler |Title of the tiddler to manipulate (defaults to the [[current tiddler|Current Tiddler]]) | -|field |The field of the //tiddler// bound to the radio button| -|min |The minimum value to be able to be set by the `<$range>` widget.| -|max |The maximum value to be able to be set by the `<$range>` widget.| -|increment |The minimum amount by which a value may be changed. Defaults to 1.| -|default |The default value displayed if the field is missing or empty.| +|field |The field of the //tiddler// bound to the radio button | +|index|<<.from-version "5.1.22">> The index of the //tiddler//, a [[DataTiddler|DataTiddlers]], to which the radio button is bound<<.tip "be sure to set the //tiddler// correctly">> | +|min |The minimum value to be able to be set by the `<$range>` widget | +|max |The maximum value to be able to be set by the `<$range>` widget | +|increment |The minimum amount by which a value may be changed. Defaults to 1 | +|default |The default value displayed if the field is missing or empty | |class |CSS classes to be assigned to the label around the radio button | ! Examples