Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecation of widgets.Text.on_submit #2446

Open
janfreyberg opened this issue Jun 16, 2019 · 5 comments
Open

Deprecation of widgets.Text.on_submit #2446

janfreyberg opened this issue Jun 16, 2019 · 5 comments

Comments

@janfreyberg
Copy link

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

@jakemiller649
Copy link

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

@janfreyberg
Copy link
Author

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?

@jakemiller649
Copy link

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

@endymion
Copy link

endymion commented Apr 4, 2023

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.

@coderunner112
Copy link

coderunner112 commented May 6, 2024

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

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

No branches or pull requests

4 participants