Skip to content

Commit

Permalink
Merge pull request #423 from apjanusz/main
Browse files Browse the repository at this point in the history
Add Select validation (#422)
  • Loading branch information
pplonski authored Feb 23, 2024
2 parents faccede + 857e76b commit 1bfba12
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 1bfba12

Please sign in to comment.