Fix Radio widget to refresh selectively, and use the checked attribute properly

publishing-framework
jeremy@jermolene.com 2021-03-07 15:49:07 +00:00
rodzic 93f4b5dac9
commit 5e4430dbf9
2 zmienionych plików z 15 dodań i 6 usunięć

Wyświetl plik

@ -41,7 +41,7 @@ RadioWidget.prototype.render = function(parent,nextSibling) {
this.inputDomNode = this.document.createElement("input");
this.inputDomNode.setAttribute("type","radio");
if(isChecked) {
this.inputDomNode.setAttribute("checked","true");
this.inputDomNode.checked = true;
}
if(this.isDisabled === "yes") {
this.inputDomNode.setAttribute("disabled",true);
@ -62,10 +62,14 @@ RadioWidget.prototype.render = function(parent,nextSibling) {
RadioWidget.prototype.getValue = function() {
var value,
tiddler = this.wiki.getTiddler(this.radioTitle);
if (this.radioIndex) {
value = this.wiki.extractTiddlerDataItem(this.radioTitle,this.radioIndex);
if(tiddler) {
if(this.radioIndex) {
value = this.wiki.extractTiddlerDataItem(this.radioTitle,this.radioIndex);
} else {
value = tiddler.getFieldString(this.radioField);
}
} else {
value = tiddler && tiddler.getFieldString(this.radioField);
value = this.radioDefault;
}
return value;
};
@ -101,6 +105,7 @@ RadioWidget.prototype.execute = function() {
this.radioIndex = this.getAttribute("index");
this.radioValue = this.getAttribute("value");
this.radioClass = this.getAttribute("class","");
this.radioDefault = this.getAttribute("default");
this.isDisabled = this.getAttribute("disabled","no");
this.radioActions = this.getAttribute("actions","");
// 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) {
var changedAttributes = this.computeAttributes();
if(($tw.utils.count(changedAttributes) > 0) || changedTiddlers[this.radioTitle]) {
if(($tw.utils.count(changedAttributes) > 0)) {
this.refreshSelf();
return true;
} else if(changedTiddlers[this.radioTitle]) {
this.inputDomNode.checked = this.getValue() === this.radioValue;
return this.refreshChildren(changedTiddlers);
} else {
return this.refreshChildren(changedTiddlers);
}

Wyświetl plik

@ -1,6 +1,6 @@
caption: radio
created: 20131212195353929
modified: 20201130184330254
modified: 20210307154753471
tags: Widgets
title: RadioWidget
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]]) |
|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//) |
|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// |
|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 |