Skip to content

Commit

Permalink
Add Select validation (#422)
Browse files Browse the repository at this point in the history
  • Loading branch information
apjanusz committed Feb 23, 2024
1 parent faccede commit 857e76b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion mercury/widgets/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from .manager import WidgetsManager

import warnings


class Select:
"""
Expand Down Expand Up @@ -88,8 +90,16 @@ class Select:
def __init__(
self, value=None, choices=[], label="Select", url_key="", disabled=False, hidden=False
):
if value is None and len(choices) > 1:
if len(choices) == 0:
raise Exception("Please provide choices list. God bless you <3")

if value is None:
value = choices[0]

if value not in choices:
value = choices[0]
warnings.warn("\nYour value is not included in choices. Automatically set value to first element from choices.")


self.code_uid = WidgetsManager.get_code_uid("Select", key=url_key)
self.url_key = url_key
Expand Down

0 comments on commit 857e76b

Please sign in to comment.