question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Default values for string Input prompt are not passed to validators

See original GitHub issue

If a defaultValue is specified in a Prompt.Input<string> call that also specifies validators, pressing Enter on the prompt sends an empty string to the validators, not the default value. For example:

var userName = Sharprompt.Prompt.Input<string>("Please enter a name", "default", validators: new[] { Sharprompt.Validations.Validators.Required()});

will fail unless providing a non-default value, since an empty string is passed to validators, rather than the default value specified by defaultValue.


I’ve created an oversimplified repro in this repo

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
shibayancommented, Dec 7, 2020

Are you saying that Confirm shows (y/N) although there is no default value?

Yes

So if I just explicitely add default: false it will work as intended?

Yes

0reactions
shibayancommented, Dec 7, 2020

The message display will be corrected in #87.

Read more comments on GitHub >

github_iconTop Results From Across the Web

If no value provided, Default value will not pass validation
I'm prompting the user to input a year in YYYY format. If the user inputs four digits everything works as expected. If the...
Read more >
Html5 validate input value not eqaul to by default value
I want to validate input value not equal to by default value through html5 validation,is it possible? <input type="text" name="First Name" value ......
Read more >
Why the number input is the worst input
If you need a number input that has no conditional validation (i.e. number is always within a certain range of min/max) and has...
Read more >
Chapter 8 – Input Validation
Input validation code checks that values entered by the user, such as text from the input() function, are formatted correctly.
Read more >
<input type="text"> - HTML: HyperText Markup Language | MDN
If no validation constraints are in place for the input (see Validation for more details), the value may be an empty string (...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found