Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

dcc.Input bug with decimal values #169

Closed
bperrenoud opened this issue Feb 26, 2018 · 7 comments · Fixed by #356
Closed

dcc.Input bug with decimal values #169

bperrenoud opened this issue Feb 26, 2018 · 7 comments · Fixed by #356

Comments

@bperrenoud
Copy link

bperrenoud commented Feb 26, 2018

when using the input component with numbers and with a callback

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

app = dash.Dash()

app.layout = html.Div([
    dcc.Input(placeholder='Enter a value...',
        type='number',
        value=0,
        step=0.01,
        id='input_id',
        style={'float': 'left'}),
    html.Div(id='my-div')
])

@app.callback(
    Output(component_id='my-div', component_property='children'),
    [Input(component_id='input_id', component_property='value')]
)
def update_output_div(input_value):
    return 'You\'ve entered "{}"'.format(input_value)

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

Try entering decimal values with some 0s in the decimal part, for instance 0.001 or 4.1004:
When the callback is triggered, any ending 0 will be removed preventing you to finish writing the number

@chriddyp
Copy link
Member

Looks like this bug was added in #100 , here:

if (type === 'number') {
setProps({value: Number(e.target.value)});
}

For now, you can use type='text' and do the casting server-side in your dash app code

@ngnpope
Copy link
Contributor

ngnpope commented Mar 8, 2018

I think the best solution here is to debounce onChange for dcc.Input().
This will allow the user to finish what they are typing before the event handler triggers.

@moorepants
Copy link

I agree with @pope1ni, the input boxes shouldn't send numbers to the server before the user has finished typing them. I'm having this trouble when entering multi digit numbers. For example, if I want to enter 20 manually, 2 gets sent to the server before I finish typing.

@steven-murray
Copy link

Any timeline for this being fixed? It is very annoying! I'd rather not do the casting server-side because it makes it harder to let the user know what went wrong to fix it.

@valentijnnieman
Copy link
Contributor

Version 0.37.0 now includes a new debounce prop on the input component, that when true, only sends back the data to the server upon 'Enter' or when losing focus. Hopefully this fixes the issues you've been having. I will close this issue now, assuming that the issue has been fixed. Thanks for your patience!

@vantaka2
Copy link

@valentijnnieman - Did .37 fix the issue? I'm using .38 and seeing this same bug.

@chriddyp
Copy link
Member

@vantaka2 - Would you mind creating a new issue with a small, reproducable example? debounce=True is indeed the way to go here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants