ipywidgets
ipywidgets copied to clipboard
Deprecation of widgets.Text.on_submit
Hi everyone,
I'm using the Text widget in a few of my projects. I often employ the on_submit method on them to register a callback that gets called when the user hits enter while the cursor is inside the text box.
There's a deprecation warning on on_submit which recommends using widget.observe(callback, 'value') with continuous_update=False instead.
Having tried to make this switch, I noticed that these aren't exactly equivalent, since widgets.Text.observe also triggers when the cursor leaves the Textbox. In my case, that's undesirable - I'd like for users to explicitly be able to submit a text field by hitting enter.
Is this deprecation of on_submit still planned? Will there be a way to replicate the previous behaviour?
Thanks very much! Jan
@janfreyberg Did you ever determine how to resolve this? Or did you just stick with on_submit?
I'm still using on_submit (and suppressing the warning).
I haven't tried switching to observe in a while. Is the issue of the value updating without hitting "Enter" still current?
Thanks for the response. Yes -- I encountered the same issue now as you did in 2019. Will just on_submit!
I, too, had to suppress the deprecation warning because I could find no working way to use observe to detect an 'enter' keystroke in an input field.
Hey I'm a little late to the party but this seems to work (assuming latest updates to python, ipywidgets)
import ipywidgets as widgets
def execute(s): print(s.new)
input2 = widgets.Text(
value='Hello World',
placeholder='Type something',
description='String:',
disabled=False,
continuous_update=False
)
input2.observe(execute,'value') input2