SolaraS
Solara•17mo 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'
            )
Was this page helpful?