Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(jans-cli-tui): dropdown raises error if not initial values provided #4142

Merged
merged 1 commit into from
Mar 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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