diff --git a/core/modules/widgets/radio.js b/core/modules/widgets/radio.js index 43b6e5dab..b943a25ed 100644 --- a/core/modules/widgets/radio.js +++ b/core/modules/widgets/radio.js @@ -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); } diff --git a/editions/tw5.com/tiddlers/widgets/RadioWidget.tid b/editions/tw5.com/tiddlers/widgets/RadioWidget.tid index 0b55e4e34..77ece4e28 100644 --- a/editions/tw5.com/tiddlers/widgets/RadioWidget.tid +++ b/editions/tw5.com/tiddlers/widgets/RadioWidget.tid @@ -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 `