Bring Drag & Drop to Dash with Dashboard Engine. 💫 Learn how at our next webinar!

Dash Button validation `valid=False` not updating

Hi , I am trying to validate a Input button group based on value, if someone entered empty space it should not be valid.

my code :

from jupyter_dash import JupyterDash
import dash_bootstrap_components as dbc
import dash_html_components as html

from dash.dependencies import Input, Output, State

app = JupyterDash(__name__,external_stylesheets=[dbc.themes.BOOTSTRAP])
app.layout = html.Div(
    [
        dbc.Input(id="validate-input",placeholder="Valid input...",  className="mb-3"),
    ]
)

@app.callback(
    Output("validate-input","valid"),
    Input("validate-input","value")
)
def validate_input(value):
    if value:
        print("value->"+value+"->"+str(len(value)))
        print("stripped->"+value.strip()+"->"+str(len(value.strip())))
        if value.strip():
            return True
        else:
            print("coming false case")
            return False
        

app.run_server(mode="jupyterlab",port=8787)

it is entering to false but not updating in UI, please help.

1 Like