Skip to content

Commit

Permalink
Add disabled parameter to select widget and browse widget (#8816)
Browse files Browse the repository at this point in the history
* Add disabled parameter to select widget and browse widget

* Add disabled attribute to edit-shortcut
  • Loading branch information
Leilei332 authored Dec 14, 2024
1 parent 3fc9523 commit c886cfe
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions core/modules/widgets/browse.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ BrowseWidget.prototype.render = function(parent,nextSibling) {
if(this.nwdirectory) {
domNode.setAttribute("nwdirectory",this.nwdirectory);
}
if(this.isDisabled === "yes") {
domNode.setAttribute("disabled", true);
}
// Add a click event handler
domNode.addEventListener("change",function (event) {
if(self.message) {
Expand Down Expand Up @@ -94,6 +97,7 @@ BrowseWidget.prototype.execute = function() {
this.accept = this.getAttribute("accept");
this.webkitdirectory = this.getAttribute("webkitdirectory");
this.nwdirectory = this.getAttribute("nwdirectory");
this.isDisabled = this.getAttribute("disabled", "no");
};

/*
Expand Down
6 changes: 5 additions & 1 deletion core/modules/widgets/edit-shortcut.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ EditShortcutWidget.prototype.render = function(parent,nextSibling) {
if(this.shortcutAriaLabel) {
this.inputNode.setAttribute("aria-label",this.shortcutAriaLabel);
}
if(this.isDisabled === "yes") {
this.inputNode.setAttribute("disabled", true);
}
// Assign the current shortcut
this.updateInputNode();
// Add event handlers
Expand Down Expand Up @@ -77,6 +80,7 @@ EditShortcutWidget.prototype.execute = function() {
this.shortcutTooltip = this.getAttribute("tooltip");
this.shortcutAriaLabel = this.getAttribute("aria-label");
this.shortcutFocus = this.getAttribute("focus");
this.isDisabled = this.getAttribute("disabled", "no");
};

/*
Expand Down Expand Up @@ -138,7 +142,7 @@ Selectively refreshes the widget if needed. Returns true if the widget needed re
*/
EditShortcutWidget.prototype.refresh = function(changedTiddlers) {
var changedAttributes = this.computeAttributes();
if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.index || changedAttributes.placeholder || changedAttributes["default"] || changedAttributes["class"] || changedAttributes.style || changedAttributes.tooltip || changedAttributes["aria-label"] || changedAttributes.focus) {
if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.index || changedAttributes.placeholder || changedAttributes["default"] || changedAttributes["class"] || changedAttributes.style || changedAttributes.tooltip || changedAttributes["aria-label"] || changedAttributes.focus || changedAttributes.disabled) {
this.refreshSelf();
return true;
} else if(changedTiddlers[this.shortcutTiddler]) {
Expand Down
6 changes: 5 additions & 1 deletion core/modules/widgets/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ SelectWidget.prototype.render = function(parent,nextSibling) {
if(this.selectMultiple) {
domNode.setAttribute("multiple","multiple");
}
if(this.isDisabled === "yes") {
domNode.setAttribute("disabled", true);
}
if(this.selectSize) {
domNode.setAttribute("size",this.selectSize);
}
Expand Down Expand Up @@ -172,6 +175,7 @@ SelectWidget.prototype.execute = function() {
this.selectTabindex = this.getAttribute("tabindex");
this.selectTooltip = this.getAttribute("tooltip");
this.selectFocus = this.getAttribute("focus");
this.isDisabled = this.getAttribute("disabled","no");
// Make the child widgets
this.makeChildWidgets();
};
Expand All @@ -182,7 +186,7 @@ Selectively refreshes the widget if needed. Returns true if the widget or any of
SelectWidget.prototype.refresh = function(changedTiddlers) {
var changedAttributes = this.computeAttributes();
// If we're using a different tiddler/field/index then completely refresh ourselves
if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.index || changedAttributes.tooltip || changedAttributes.tabindex) {
if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.index || changedAttributes.tooltip || changedAttributes.tabindex || changedAttributes.disabled) {
this.refreshSelf();
return true;
} else {
Expand Down
1 change: 1 addition & 0 deletions editions/tw5.com/tiddlers/widgets/BrowseWidget.tid
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The content of the <<.wid BrowseWidget>> widget is ignored.
|accept |<<.from-version "5.1.23">> Optional comma delimited [[list of file accepted extensions|https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#Unique_file_type_specifiers]] and/or MIME types |
|message |Optional override of widget message to be generated. The files will be passed in the JavaScript object `event.target.files` |
|param |Optional parameter to be passed with the custom message |
|disabled |<<.from-version "5.3.7">> Optional. Set to "yes" to disable file browser. Defaults to "no". |
|data-* |<<.from-version "5.3.2">> Optional [[data attributes|https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes]] to be assigned to the HTML element |
|style.* |<<.from-version "5.3.2">> Optional [[CSS properties|https://developer.mozilla.org/en-US/docs/Web/CSS/Reference]] to be assigned to the HTML element |

Expand Down
1 change: 1 addition & 0 deletions editions/tw5.com/tiddlers/widgets/SelectWidget.tid
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ The content of the `<$select>` widget should be one or more HTML `<option>` or `
|actions |A string containing ActionWidgets to be triggered when the key combination is detected |
|focus |<<.from-version "5.2.4">> Optional. Set to "yes" to automatically focus the HTML select element after creation |
|tabindex |<<.from-version "5.3.1">> Optional. Sets the `tabindex` attribute of the HTML select element to the given value |
|disabled |<<.from-version "5.3.7">> Optional. Set to "yes" to disable select input. Defaults to "no". |
|data-* |<<.from-version "5.3.2">> Optional [[data attributes|https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes]] to be assigned to the HTML element |
|style.* |<<.from-version "5.3.2">> Optional [[CSS properties|https://developer.mozilla.org/en-US/docs/Web/CSS/Reference]] to be assigned to the HTML element |

Expand Down

0 comments on commit c886cfe

Please sign in to comment.