prompt-toolkit / prompt-toolkit/python-prompt-toolkit

input_dialog validation issues

Open
#1,753 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
10.6k
Forks
815
PR merge metrics
No merged PRs in 30d

Description

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 :)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the input_dialog implementation and its ok_handler entry point, then inspect how the TextArea buffer currently validates on submission. Done means clicking OK with either mouse or keyboard triggers validation, returns the text only when valid, and restores focus to the TextArea after a validation error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.