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

Option to not clear the prompt when validation false #374

Closed
mhkeller opened this issue May 23, 2016 · 6 comments · Fixed by #1618
Closed

Option to not clear the prompt when validation false #374

mhkeller opened this issue May 23, 2016 · 6 comments · Fixed by #1618

Comments

@mhkeller
Copy link

Currently when an answer false validation, the answer the user has given is also cleared. An option to have the user input remain so that it could be edited would be helpful.

My use case is that I'm asking the user to fill out text for a sample tweet with validation that the text is less than 140 characters. If the string is over 140, I give an error message with the current character count. For the user, it would be nice if they could edit the text string and resubmit instead of having their entry get cleared and have to start again.

@rohmanhm
Copy link

I agreed with @mhkeller .
Are there any options to clear the screen after user submit an answer?

@SBoudrias
Copy link
Owner

PR welcomed. I think the default behavior should be updated to not clear the initial answer.

@rebgrasshopper
Copy link

I get the opposite behavior - the input does not clear upon validation error. Was there a change that made this the default behavior?

@SBoudrias
Copy link
Owner

It's possible different prompts have different behaviors; or the stable version (inquirer) VS the beta ones (@inquirer/input).

Any of this would explain the different behavior?

Also anyone has strong opinion the input should be cleared? If so, we could consider adding as a configuration option

@brendaHuang-2023
Copy link

brendaHuang-2023 commented Sep 25, 2024

I'd like to have the input cleared. Otherwise when user enters an invalid input, we have to ask the user to clear the input and retype, which is not the best user experience.

Plus, keepAnswerOnValidationError is not working.

@SBoudrias
Copy link
Owner

Alright! To summarize the need if someone wants to send a PR:

  1. Expose an option on @inquirer/input to control the behavior on validation failure. (2 cents: validationError: 'clear' | 'keep', default on keep. - Feel free to suggest a better naming for the options!)
  2. Implement both a clear, and keep content option.

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