From d1171128c60e1f9f124c8a951a71a4609cd8bd1f Mon Sep 17 00:00:00 2001 From: Simon Hoxbro Date: Sat, 12 Dec 2020 15:30:28 +0100 Subject: [PATCH 1/2] Fixing enable and disable file download --- panel/models/file_download.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/panel/models/file_download.ts b/panel/models/file_download.ts index 6bca0526b3..3f338121d1 100644 --- a/panel/models/file_download.ts +++ b/panel/models/file_download.ts @@ -1,6 +1,7 @@ import {InputWidget, InputWidgetView} from "@bokehjs/models/widgets/input_widget" import {bk_btn, bk_btn_type} from "@bokehjs/styles/buttons" +import {input} from "@bokehjs/core/dom" import {ButtonType} from "@bokehjs/core/enums" import * as p from "@bokehjs/core/properties" @@ -34,6 +35,8 @@ export class FileDownloadView extends InputWidgetView { _prev_href: string | null = "" _prev_download: string | null = "" + protected input_el: HTMLInputElement + initialize(): void { super.initialize() if ( this.model.data && this.model.filename ) { @@ -47,6 +50,7 @@ export class FileDownloadView extends InputWidgetView { this.connect(this.model.properties.filename.change, () => this._update_download()) this.connect(this.model.properties._transfers.change, () => this._handle_click()) this.connect(this.model.properties.label.change, () => this._update_label()) + this.connect(this.model.properties.disabled.change, () => this.set_disabled()) } render(): void { @@ -96,6 +100,12 @@ export class FileDownloadView extends InputWidgetView { this.anchor_el.addEventListener("click", this._click_listener) } this.group_el.appendChild(this.anchor_el) + + this.input_el = input({ + type: "bk_btn, bk_btn_type", + disabled: this.model.disabled, + }) + this.input_el.addEventListener("change", () => this.change_input()) } _increment_clicks() : void { @@ -166,6 +176,14 @@ export class FileDownloadView extends InputWidgetView { } } } + + set_disabled(): void { + if (this.model.disabled){ + this.anchor_el.setAttribute("disabled", "") + } else { + this.anchor_el.removeAttribute("disabled") + } + } } export namespace FileDownload { From 9b2a2362d73b2687132352090fa576204c516775 Mon Sep 17 00:00:00 2001 From: Simon Hoxbro Date: Sat, 12 Dec 2020 15:40:36 +0100 Subject: [PATCH 2/2] Added comment --- panel/models/file_download.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/panel/models/file_download.ts b/panel/models/file_download.ts index 3f338121d1..5ba4a50c46 100644 --- a/panel/models/file_download.ts +++ b/panel/models/file_download.ts @@ -101,9 +101,12 @@ export class FileDownloadView extends InputWidgetView { } this.group_el.appendChild(this.anchor_el) + // If this is not added it will give the following error + // "Uncaught TypeError: t is undefined" + // This seems to be related to button do not have a value + // property. this.input_el = input({ type: "bk_btn, bk_btn_type", - disabled: this.model.disabled, }) this.input_el.addEventListener("change", () => this.change_input()) }