diff --git a/core/modules/widgets/radio.js b/core/modules/widgets/radio.js index c22aa5ecb..43b6e5dab 100644 --- a/core/modules/widgets/radio.js +++ b/core/modules/widgets/radio.js @@ -13,7 +13,6 @@ Set a field or index at a given tiddler via radio buttons "use strict"; var Widget = require("$:/core/modules/widgets/widget.js").widget; - var RadioWidget = function(parseTreeNode,options) { this.initialise(parseTreeNode,options); }; @@ -37,8 +36,8 @@ RadioWidget.prototype.render = function(parent,nextSibling) { // Create our elements this.labelDomNode = this.document.createElement("label"); this.labelDomNode.setAttribute("class", - "tc-radio " + this.radioClass + (isChecked ? " tc-radio-selected" : "") - ); + "tc-radio " + this.radioClass + (isChecked ? " tc-radio-selected" : "") + ); this.inputDomNode = this.document.createElement("input"); this.inputDomNode.setAttribute("type","radio"); if(isChecked) { @@ -86,6 +85,10 @@ RadioWidget.prototype.handleChangeEvent = function(event) { if(this.inputDomNode.checked) { this.setValue(); } + // Trigger actions + if(this.radioActions) { + this.invokeActionString(this.radioActions,this,event,{"actionValue": this.radioValue}); + } }; /* @@ -99,6 +102,7 @@ RadioWidget.prototype.execute = function() { this.radioValue = this.getAttribute("value"); this.radioClass = this.getAttribute("class",""); this.isDisabled = this.getAttribute("disabled","no"); + this.radioActions = this.getAttribute("actions",""); // Make the child widgets this.makeChildWidgets(); }; @@ -108,16 +112,11 @@ Selectively refreshes the widget if needed. Returns true if the widget or any of */ RadioWidget.prototype.refresh = function(changedTiddlers) { var changedAttributes = this.computeAttributes(); - if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.index || changedAttributes.value || changedAttributes["class"] || changedAttributes.disabled) { + if(($tw.utils.count(changedAttributes) > 0) || changedTiddlers[this.radioTitle]) { this.refreshSelf(); return true; } else { - var refreshed = false; - if(changedTiddlers[this.radioTitle]) { - this.inputDomNode.checked = this.getValue() === this.radioValue; - refreshed = true; - } - return this.refreshChildren(changedTiddlers) || refreshed; + return this.refreshChildren(changedTiddlers); } };