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

Require typed answer for confirm question #312

Open
redace0001 opened this issue Aug 28, 2023 · 3 comments
Open

Require typed answer for confirm question #312

redace0001 opened this issue Aug 28, 2023 · 3 comments
Labels
Enhancement New feature or request

Comments

@redace0001
Copy link

Describe the problem

When I use the "confirm" question, I can force the user to use the "Enter" key to answer the question but I cannot require him to type anything at all.
If the user decides to just spam "Enter", all defaults values will be used instead.

For some important confirmations like "Are you sure you want to delete that file ?" or something similar, I want to be sure the user types something to answer (y/n or Yes/no) and cannot press Enter only.

I can set the default value to None (or anything different from True/False) and detect that answer but I would need to re-throw the question again instead of locking the user in the question.

"validate" isn't supported in "confirms" also

Basically I would need for a "y/n" instead of a "Y/n" or "y/N".

Describe the solution

Add a "mandatory" argument of sort to the "confirm" type to force the user to type something and not leave the answer empty.

Alternatives considered

Using a custom text question or choice question but this basically feels like reinventing the wheel at that point.
The first solution I had was to re-throw the same question until it is answered correctly like I said before but that's not "pretty".

@redace0001 redace0001 added the Enhancement New feature or request label Aug 28, 2023
@redace0001
Copy link
Author

I just checked the related code and it seems that it would be pretty easy to re-implement the "confirm" class to suit my needs as I just need to change the check for None in result and refuse to accept the answer if that is the case.

I will do this for my project but I think it might be a good idea to add that functionality to the original code still.

@kiancross
Copy link
Collaborator

@redace0001 If you think your changes are generic, feel free to submit a PR!

@redace0001
Copy link
Author

Hello.

The code I implemented for my case is pretty custom so I don't think it fits the "generic" tag.
I'll think about trying to modify the original code myself for a PR when I have time.

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

No branches or pull requests

2 participants