ipywidgets icon indicating copy to clipboard operation
ipywidgets copied to clipboard

Deprecation of widgets.Text.on_submit

Open janfreyberg opened this issue 6 years ago • 5 comments
trafficstars

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 avatar Jun 16 '19 08:06 janfreyberg

@janfreyberg Did you ever determine how to resolve this? Or did you just stick with on_submit?

jakemiller649 avatar Apr 08 '21 19:04 jakemiller649

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?

janfreyberg avatar Apr 09 '21 06:04 janfreyberg

Thanks for the response. Yes -- I encountered the same issue now as you did in 2019. Will just on_submit!

jakemiller649 avatar Apr 09 '21 13:04 jakemiller649

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.

endymion avatar Apr 04 '23 20:04 endymion

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

coderunner112 avatar May 06 '24 09:05 coderunner112