mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 10:07:19 +00:00
Fix Radio widget to refresh selectively, and use the checked attribute properly
This commit is contained in:
parent
93f4b5dac9
commit
5e4430dbf9
@ -41,7 +41,7 @@ RadioWidget.prototype.render = function(parent,nextSibling) {
|
|||||||
this.inputDomNode = this.document.createElement("input");
|
this.inputDomNode = this.document.createElement("input");
|
||||||
this.inputDomNode.setAttribute("type","radio");
|
this.inputDomNode.setAttribute("type","radio");
|
||||||
if(isChecked) {
|
if(isChecked) {
|
||||||
this.inputDomNode.setAttribute("checked","true");
|
this.inputDomNode.checked = true;
|
||||||
}
|
}
|
||||||
if(this.isDisabled === "yes") {
|
if(this.isDisabled === "yes") {
|
||||||
this.inputDomNode.setAttribute("disabled",true);
|
this.inputDomNode.setAttribute("disabled",true);
|
||||||
@ -62,10 +62,14 @@ RadioWidget.prototype.render = function(parent,nextSibling) {
|
|||||||
RadioWidget.prototype.getValue = function() {
|
RadioWidget.prototype.getValue = function() {
|
||||||
var value,
|
var value,
|
||||||
tiddler = this.wiki.getTiddler(this.radioTitle);
|
tiddler = this.wiki.getTiddler(this.radioTitle);
|
||||||
if (this.radioIndex) {
|
if(tiddler) {
|
||||||
value = this.wiki.extractTiddlerDataItem(this.radioTitle,this.radioIndex);
|
if(this.radioIndex) {
|
||||||
|
value = this.wiki.extractTiddlerDataItem(this.radioTitle,this.radioIndex);
|
||||||
|
} else {
|
||||||
|
value = tiddler.getFieldString(this.radioField);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
value = tiddler && tiddler.getFieldString(this.radioField);
|
value = this.radioDefault;
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
};
|
};
|
||||||
@ -101,6 +105,7 @@ RadioWidget.prototype.execute = function() {
|
|||||||
this.radioIndex = this.getAttribute("index");
|
this.radioIndex = this.getAttribute("index");
|
||||||
this.radioValue = this.getAttribute("value");
|
this.radioValue = this.getAttribute("value");
|
||||||
this.radioClass = this.getAttribute("class","");
|
this.radioClass = this.getAttribute("class","");
|
||||||
|
this.radioDefault = this.getAttribute("default");
|
||||||
this.isDisabled = this.getAttribute("disabled","no");
|
this.isDisabled = this.getAttribute("disabled","no");
|
||||||
this.radioActions = this.getAttribute("actions","");
|
this.radioActions = this.getAttribute("actions","");
|
||||||
// Make the child widgets
|
// Make the child widgets
|
||||||
@ -112,9 +117,12 @@ Selectively refreshes the widget if needed. Returns true if the widget or any of
|
|||||||
*/
|
*/
|
||||||
RadioWidget.prototype.refresh = function(changedTiddlers) {
|
RadioWidget.prototype.refresh = function(changedTiddlers) {
|
||||||
var changedAttributes = this.computeAttributes();
|
var changedAttributes = this.computeAttributes();
|
||||||
if(($tw.utils.count(changedAttributes) > 0) || changedTiddlers[this.radioTitle]) {
|
if(($tw.utils.count(changedAttributes) > 0)) {
|
||||||
this.refreshSelf();
|
this.refreshSelf();
|
||||||
return true;
|
return true;
|
||||||
|
} else if(changedTiddlers[this.radioTitle]) {
|
||||||
|
this.inputDomNode.checked = this.getValue() === this.radioValue;
|
||||||
|
return this.refreshChildren(changedTiddlers);
|
||||||
} else {
|
} else {
|
||||||
return this.refreshChildren(changedTiddlers);
|
return this.refreshChildren(changedTiddlers);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
caption: radio
|
caption: radio
|
||||||
created: 20131212195353929
|
created: 20131212195353929
|
||||||
modified: 20201130184330254
|
modified: 20210307154753471
|
||||||
tags: Widgets
|
tags: Widgets
|
||||||
title: RadioWidget
|
title: RadioWidget
|
||||||
type: text/vnd.tiddlywiki
|
type: text/vnd.tiddlywiki
|
||||||
@ -17,6 +17,7 @@ The content of the `<$radio>` widget is displayed within an HTML `<label>` eleme
|
|||||||
|tiddler |Title of the tiddler to manipulate (defaults to the [[current tiddler|Current Tiddler]]) |
|
|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 |
|
|field |The field of the //tiddler// bound to the radio button |
|
||||||
|index|<<.from-version "5.1.14">> The index of the //tiddler// being [[DataTiddler|DataTiddlers]] bound to the radio button (takes precedence over //field//) |
|
|index|<<.from-version "5.1.14">> The index of the //tiddler// being [[DataTiddler|DataTiddlers]] bound to the radio button (takes precedence over //field//) |
|
||||||
|
|default |<<.from-version "5.1.24">> The default value to be used for matching if the tiddler, field or index are missing |
|
||||||
|value |The value for the //field// or //index// of the //tiddler// |
|
|value |The value for the //field// or //index// of the //tiddler// |
|
||||||
|class |The CSS classes assigned to the label around the radio button <<.from-version "5.1.14">> `tc-radio` is always applied by default, as well as `tc-radio-selected` when selected |
|
|class |The CSS classes assigned to the label around the radio button <<.from-version "5.1.14">> `tc-radio` is always applied by default, as well as `tc-radio-selected` when selected |
|
||||||
|actions|<<.from-version "5.1.23">> Optional string containing ActionWidgets to be triggered when the value changes. <br>The variable: ''actionValue'' is available for the actions |
|
|actions|<<.from-version "5.1.23">> Optional string containing ActionWidgets to be triggered when the value changes. <br>The variable: ''actionValue'' is available for the actions |
|
||||||
|
Loading…
Reference in New Issue
Block a user