prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.11k stars 717 forks source link

input_dialog validation issues #1753

Open eldadweiss opened 1 year ago

eldadweiss commented 1 year ago

Hi,

when using input_dialog validation there is a bug where text validation does not occur upon clicking the OK button (With mouse or keyboard).

My suggested solution to fix this issue is to change the ok_handler method of the input_dialog so :

  1. A new validation will occur upon clicking on the OK button
  2. In case of validation error that focus will be brought back to the TextArea control
def ok_handler() -> None:
        textfield.buffer.validate() # ---------> Perform validation
        if textfield.buffer.validation_error is None: # ---------> Check for validation errors
            get_app().exit(result=textfield.text)
        else:
            get_app().layout.focus(textfield) # -------------> Bring back the focus to the TextArea control

Thanks in advance :)