Skip to content

Commit

Permalink
fix(jans-cli-tui): dropdown widget raises error if not initial values…
Browse files Browse the repository at this point in the history
… provided (#4142)
  • Loading branch information
devrimyatar authored Mar 14, 2023
1 parent 86a7f18 commit 0aa51eb
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions jans-cli-tui/cli_tui/wui_components/jans_drop_down.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from typing import TypeVar, Callable

import cli_style
from utils.multi_lang import _

class JansSelectBox:
"""_summary_
Expand Down Expand Up @@ -139,15 +140,18 @@ def __init__(
self._value = value
self.on_value_changed = on_value_changed
if select_one_option:
self.value_list.insert(0, (None, 'Select One'))
self.value_list.insert(0, (None, _("Select One")))

if not self.value_list:
self.display_value = _("No option was provided")

for val in self.value_list:
if val[0] == value:
self.display_value = val[1]
break
else:
if select_one_option:
self.display_value = self.value_list[0][1] if self.value_list else "Enter to Select"
self.display_value = self.value_list[0][1] if self.value_list else _("Enter to Select")

self.dropdown = True
self.window = Window(
Expand Down Expand Up @@ -185,6 +189,14 @@ def value(
)-> None:
self._value = value
self.select_box.set_value(value)
for val in self.value_list:
if val[0] == value:
self.display_value = val[1]
break
else:
if self.value_list:
self.display_value = self.value_list[0][1]

if self.on_value_changed:
self.on_value_changed(value)

Expand Down

0 comments on commit 0aa51eb

Please sign in to comment.