S
Solara•4mo ago
Cezik

Solara Error

Hey 👋 , I have encountered a problem that I have not found in Github issues or on discord. I created a page that has a form with a dozen fields (select, input, slider) and a button at the very bottom of the page. When it is clicked, these fields are validated (that the values are not empty, etc.) and during if an exception is thrown I run solara.Error(label='message') however it is not visible anywhere (I am sure it goes into the except block in try except). I paste the simplified code below. Any help would be appreciated! 🫂
@solara.component
def Page():
openai_api_key_value = solara.reactive('')

def validate_form() -> bool:
try:
raise InvalidSetting.invalid_api_key('test', 'message')
except InvalidSetting as e:
print('test_print')
solara.Error(label='error during validation')
return False

return True

def submit_form():
if validate_form():
solara.Success(label='Saved')

# View
header.Header('Settings')
sidebar.Sidebar('Settings')

with solara.Column(margin=10):
Title('AI 🧬')

SubTitle('OpenAI')
solara.InputText(
label='OpenAI API Key',
value=openai_api_key_value
)

with solara.Column(align='end'):
solara.Button(
'Submit',
on_click=submit_form,
outlined=True,
color='primary'
)
@solara.component
def Page():
openai_api_key_value = solara.reactive('')

def validate_form() -> bool:
try:
raise InvalidSetting.invalid_api_key('test', 'message')
except InvalidSetting as e:
print('test_print')
solara.Error(label='error during validation')
return False

return True

def submit_form():
if validate_form():
solara.Success(label='Saved')

# View
header.Header('Settings')
sidebar.Sidebar('Settings')

with solara.Column(margin=10):
Title('AI 🧬')

SubTitle('OpenAI')
solara.InputText(
label='OpenAI API Key',
value=openai_api_key_value
)

with solara.Column(align='end'):
solara.Button(
'Submit',
on_click=submit_form,
outlined=True,
color='primary'
)
1 Reply
Cezik
CezikOP•4mo ago
I solved the problem! Below I paste the solution should anyone ever run into a similar problem:
@solara.component
def Page():
openai_api_key_value = solara.reactive('')
show_error = solara.reactive('')

def validate_form() -> bool:
try:
raise InvalidSetting.invalid_api_key('test', 'message')
except InvalidSetting as e:
show_error.set(str(e))
return False

return True

def submit_form():
if validate_form():
solara.Success(label='Saved')

# View
header.Header('Settings')
sidebar.Sidebar('Settings')

with solara.Column(margin=10):
Title('AI 🧬')

SubTitle('OpenAI')
solara.InputText(
label='OpenAI API Key',
value=openai_api_key_value
)

if show_error.value:
solara.Error(label=show_error.value)

with solara.Column(align='end'):
solara.Button(
'Submit',
on_click=submit_form,
outlined=True,
color='primary'
)
@solara.component
def Page():
openai_api_key_value = solara.reactive('')
show_error = solara.reactive('')

def validate_form() -> bool:
try:
raise InvalidSetting.invalid_api_key('test', 'message')
except InvalidSetting as e:
show_error.set(str(e))
return False

return True

def submit_form():
if validate_form():
solara.Success(label='Saved')

# View
header.Header('Settings')
sidebar.Sidebar('Settings')

with solara.Column(margin=10):
Title('AI 🧬')

SubTitle('OpenAI')
solara.InputText(
label='OpenAI API Key',
value=openai_api_key_value
)

if show_error.value:
solara.Error(label=show_error.value)

with solara.Column(align='end'):
solara.Button(
'Submit',
on_click=submit_form,
outlined=True,
color='primary'
)
Want results from more Discord servers?
Add your server