1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-25 23:03:15 +00:00

Range widget: fix refreshing

The range widget wasn't refreshing correctly when the underlying tiddler value changed
This commit is contained in:
Jeremy Ruston 2019-11-02 09:31:15 +00:00
parent 43d18e74d5
commit e84c422e50

View File

@ -47,11 +47,9 @@ RangeWidget.prototype.render = function(parent,nextSibling) {
this.inputDomNode.setAttribute("step", this.increment); this.inputDomNode.setAttribute("step", this.increment);
} }
this.inputDomNode.value = this.getValue(); this.inputDomNode.value = this.getValue();
// Add a click event handler // Add a click event handler
$tw.utils.addEventListeners(this.inputDomNode,[ $tw.utils.addEventListeners(this.inputDomNode,[
{name: "input", handlerObject: this, handlerMethod: "handleChangeEvent"} {name: "input", handlerObject: this, handlerMethod: "handleInputEvent"}
]); ]);
// Insert the label into the DOM and render any children // Insert the label into the DOM and render any children
parent.insertBefore(this.inputDomNode,nextSibling); parent.insertBefore(this.inputDomNode,nextSibling);
@ -60,10 +58,11 @@ RangeWidget.prototype.render = function(parent,nextSibling) {
RangeWidget.prototype.getValue = function() { RangeWidget.prototype.getValue = function() {
var tiddler = this.wiki.getTiddler(this.tiddlerTitle), var tiddler = this.wiki.getTiddler(this.tiddlerTitle),
fieldName = this.tiddlerField || "text",
value = this.defaultValue; value = this.defaultValue;
if(tiddler) { if(tiddler) {
if($tw.utils.hop(tiddler.fields,this.tiddlerField)) { if($tw.utils.hop(tiddler.fields,fieldName)) {
value = tiddler.fields[this.tiddlerField] || ""; value = tiddler.fields[fieldName] || "";
} else { } else {
value = this.defaultValue || ""; value = this.defaultValue || "";
} }
@ -71,8 +70,10 @@ RangeWidget.prototype.getValue = function() {
return value; return value;
}; };
RangeWidget.prototype.handleChangeEvent = function(event) { RangeWidget.prototype.handleInputEvent = function(event) {
this.wiki.setText(this.tiddlerTitle ,this.tiddlerField, null,this.inputDomNode.value); if(this.getValue() !== this.inputDomNode.value) {
this.wiki.setText(this.tiddlerTitle,this.tiddlerField,null,this.inputDomNode.value);
}
}; };
/* /*
@ -102,7 +103,10 @@ RangeWidget.prototype.refresh = function(changedTiddlers) {
} else { } else {
var refreshed = false; var refreshed = false;
if(changedTiddlers[this.tiddlerTitle]) { if(changedTiddlers[this.tiddlerTitle]) {
this.inputDomNode.checked = this.getValue(); var value = this.getValue();
if(this.inputDomNode.value !== value) {
this.inputDomNode.value = value;
}
refreshed = true; refreshed = true;
} }
return this.refreshChildren(changedTiddlers) || refreshed; return this.refreshChildren(changedTiddlers) || refreshed;