From 075a420d4b9553cc8777d6207fce37b68781a7e9 Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Thu, 27 Apr 2023 23:50:16 +0800 Subject: [PATCH] Opt: Leave only one option if a select is disabled to stop people from asking why event is not selectable --- module/webui/widgets.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/module/webui/widgets.py b/module/webui/widgets.py index 90dddbf02..335c7e7b1 100644 --- a/module/webui/widgets.py +++ b/module/webui/widgets.py @@ -333,15 +333,25 @@ def put_arg_select(kwargs: T_Output_Kwargs) -> Output: disabled: bool = kwargs.pop("disabled", False) _: str = kwargs.pop("invalid_feedback", None) - option = [] - if options: - for opt, label in zip(options, options_label): - o = {"label": label, "value": opt} - if value == opt: - o["selected"] = True - else: - o["disabled"] = disabled - option.append(o) + if disabled: + label = value + for opt, opt_label in zip(options, options_label): + if opt == value: + label = opt_label + break + option = [{ + "label": label, + "value": value, + "selected": True, + }] + else: + option = [] + if options: + for opt, label in zip(options, options_label): + o = {"label": label, "value": opt} + if value == opt: + o["selected"] = True + option.append(o) kwargs["options"] = option return put_scope(