Add "index" attribute to range widget

fix-syncer
Jeremy Ruston 2019-11-04 18:56:22 +00:00
rodzic 7beee4f9ce
commit bfbd886a8b
2 zmienionych plików z 22 dodań i 12 usunięć

Wyświetl plik

@ -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;
})();
})();

Wyświetl plik

@ -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