Multi-Value vs. Default Dropbox, using confirm-dialog causes an error

Maybe I’m missing something fundamental, but I simply don’t know an answer. Therefore it would be very kind if someone could help me out:

I’m trying to adapt a feature provided by @adamschroeder on his YouTube-Channel : https://www.youtube.com/watch?v=NuoA08b-cMM
In his example the confirm-dialog pops up if no variables are selected by the Multi-Value Dropdown. I like this idea and would like to use it for my own app and Default Dropdowns.

The simplified Multi-Value Dropdown code looks like this:

import dash
import dash_html_components as html
import dash_core_components as dcc
from dash.dependencies import Input, Output

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div([
    dcc.ConfirmDialog(
        id='confirm-dialog',
        displayed=False,
        message='Please choose Dropdown variables!',
    ),
    
    dcc.Dropdown(
        id='demo-dropdown',
       options=[
            {'label': 'New York City', 'value': 'NYC'},
            {'label': 'Montréal', 'value': 'MTL'},
            {'label': 'San Francisco', 'value': 'SF'}
        ],
         multi=True,
        value="MTL"
    ),  
    html.Div(id='dd-output-container')
])


@app.callback(
    Output('confirm-dialog','displayed'),
    Output('dd-output-container', 'children'),
    [Input('demo-dropdown', 'value')])
def update_output(value):
    if len(value) > 0:
        return False, 'You have selected "{}"'.format(value)
    if len(value)==0:
        return True, dash.no_update
        
       

if __name__ == '__main__':
    app.run_server(debug=False)

BUT if I apply the same idea on a Default Dropdown:

dcc.Dropdown(
        id='demo-dropdown',
       options=[
            {'label': 'New York City', 'value': 'NYC'},
            {'label': 'Montréal', 'value': 'MTL'},
            {'label': 'San Francisco', 'value': 'SF'}
        ],
#         multi=True,
        value="MTL"
    ),  

I only get this error:

TypeError: object of type ‘NoneType’ has no len()

And the cofirm-dialog doesn’t pop up if no variable is selected…
Does someone understand why ‘value’ is ‘None’ is this case?
Thanks a lot!

I did some further research:
With the “clearable” property of the dropdown the idea becomes obsolete.

But nevertheless, the first idea should also work, no?

Hi @jack2704,

When you # the multi=True, the default is multi=False, which means the value chosen would be a string type, not a list type. That is why len(value) doesn’t work, especially if no value is chosen. Before, when multi=True, the values are inside a list, so len(value) makes sense, but not with a string.

Try this:

def update_output(value):
    print(value)
    print(type(value))
    if value:
        return False, 'You have selected "{}"'.format(value)
    if value is None:
        return True, dash.no_update

aww… silly me. Thanks for helping me out @adamschroeder!!!