mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 10:07:19 +00:00
Range widget: fix refreshing
The range widget wasn't refreshing correctly when the underlying tiddler value changed
This commit is contained in:
parent
43d18e74d5
commit
e84c422e50
@ -47,11 +47,9 @@ RangeWidget.prototype.render = function(parent,nextSibling) {
|
||||
this.inputDomNode.setAttribute("step", this.increment);
|
||||
}
|
||||
this.inputDomNode.value = this.getValue();
|
||||
|
||||
|
||||
// Add a click event handler
|
||||
$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
|
||||
parent.insertBefore(this.inputDomNode,nextSibling);
|
||||
@ -60,10 +58,11 @@ RangeWidget.prototype.render = function(parent,nextSibling) {
|
||||
|
||||
RangeWidget.prototype.getValue = function() {
|
||||
var tiddler = this.wiki.getTiddler(this.tiddlerTitle),
|
||||
fieldName = this.tiddlerField || "text",
|
||||
value = this.defaultValue;
|
||||
if(tiddler) {
|
||||
if($tw.utils.hop(tiddler.fields,this.tiddlerField)) {
|
||||
value = tiddler.fields[this.tiddlerField] || "";
|
||||
if($tw.utils.hop(tiddler.fields,fieldName)) {
|
||||
value = tiddler.fields[fieldName] || "";
|
||||
} else {
|
||||
value = this.defaultValue || "";
|
||||
}
|
||||
@ -71,8 +70,10 @@ RangeWidget.prototype.getValue = function() {
|
||||
return value;
|
||||
};
|
||||
|
||||
RangeWidget.prototype.handleChangeEvent = function(event) {
|
||||
this.wiki.setText(this.tiddlerTitle ,this.tiddlerField, null,this.inputDomNode.value);
|
||||
RangeWidget.prototype.handleInputEvent = function(event) {
|
||||
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 {
|
||||
var refreshed = false;
|
||||
if(changedTiddlers[this.tiddlerTitle]) {
|
||||
this.inputDomNode.checked = this.getValue();
|
||||
var value = this.getValue();
|
||||
if(this.inputDomNode.value !== value) {
|
||||
this.inputDomNode.value = value;
|
||||
}
|
||||
refreshed = true;
|
||||
}
|
||||
return this.refreshChildren(changedTiddlers) || refreshed;
|
||||
|
Loading…
Reference in New Issue
Block a user