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

Combining an input limit to my multi-dropdown callback is not functioning

trying to limit the amount of inputs a user can enter in my multi-dropdown. In my code below, I have it set to 4 values MAX!

This code doesn’t bring back errors, but it’s not functioning like I want it to. I want the callback to stop users from entering more inputs once the number exceeds 4.

@app.callback(
    [dash.dependencies.Output("input-warning", "children"),
    dash.dependencies.Output("dynamic-dropdown", "options")],
    [dash.dependencies.Input("dynamic-dropdown", "search_value")],
    [dash.dependencies.State("dynamic-dropdown", "value")],
)
def update_multi_options(search_value, value):
    conn.rollback()
    if search_value is None:
        raise PreventUpdate
    elif len(value) >= 4:
        children = html.P("limit reached",id='input-warning')
        return [children, [o for o in OPTIONS if o["value"] in value]]  
    else:
    # Make sure that the set values are in the option list, else they will disappear
    # from the shown select list, but still part of the `value`.
        return [
            o for o in OPTIONS if search_value.upper() in o["label"].upper() or o["value"] in (value or [])
        ]

I made an elif conditional to try and limit the inputs, I couldn’t get it to work however.

Would greatly appreciate some guidance on why my code doesn’t achieve what I want it to.