Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

I've noticed a few things about some keyboard interaction and text inputs that prompt questions.

Mere curiosity

  • Why use textarea for single-line text input, rather than just an input with type=text?

Enhanced features

  • Some keyboard-related events could use more fields. The other day I subclassed one of the widgets (don't recall which) so that oninput (I think?) returned more than just the value. For backward compatibility, though, I'm not sure this is feasible.
  • A request_focus() method that wraps the .focus() method for HTML elements would be very convenient. Consider a document with multiple TextInputs; when onchange occurs in one, the handler could automatically focus on the next one, rather than forcing the user to do that somehow.
  • Is it worth allowing keyboard events on more widgets, or incorporating intuitive behavior when the widget is focused? For example, when the Slider widget is focused, it makes sense to have it respond to onkeydown; I have an ExtendedSlider that uses this to:
    • Move left or right when the arrow key is pressed.
    • Move to a position according to a number pressed. (I don't think this should be a default behavior, but it's an example.)
You must be logged in to vote

Replies: 1 comment · 1 reply

Comment options

It is not required to trigger the event in orther to get back the widget result. You can simply use get_value on python side. So, if you need the value of all the widgets in a form, call get_value for each one.
However, using the focus on multiple widgets is not possible. The focus is related to some internal ui update functionality.

You must be logged in to vote
1 reply
@johnperry-math
Comment options

You can simply use get_value on python side.

Odd. I was struggling with this just yesterday, and resolved it only by adding a value to onkeydown for the ExtendedTextInput class I use. Granted, that might not have been the ultimate issue; the main problem turned out to be a different issue.

However, using the focus on multiple widgets is not possible. The focus is related to some internal ui update functionality.

Perhaps I wasn't clear, because I don't want to focus on multiple widgets at once. I just want to be able to invoke focus, period.

I guess you're referring to these lines in gui.py (starting at 1435):

}else if( received_msg[0]=='1' ){ /*update_widget*/
    // ... snip
    var elemToFocus = document.getElementById(focusedElement);
    if( elemToFocus != null ){
        elemToFocus.focus();
        try{
            elemToFocus = document.getElementById(focusedElement);
            if(caretStart>-1 && caretEnd>-1) elemToFocus.setSelectionRange(caretStart, caretEnd);
        }catch(e){console.debug(e.message);}
    }

The functionality I want seems to work when I add the following code to Extended... widgets that I create by subclassing remi's widgets:

    def focus(self, app_instance):
        app_instance.execute_javascript(
            """
            // need a timeout in case it was previously disabled
            setTimeout(() => {
                el = document.getElementById('%(id)s');
                el.focus();
            }, 100)
        """ % {"id": self.identifier}
        )

But I could definitely be missing something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
💡
Ideas
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.