-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Number type in CLI can not be deleted. #866
Comments
That being said, it's possible something is wrong when we end up printing the number on the terminal. I do not think this is related to the type of |
I got the same error, after fails validation, the cli shows my code: const inquirer = require("inquirer");
const getTourId = async (inputs = []) => {
const prompts = [
{
type: 'number',
name: 'value',
message: "Tour Id?",
validate: function(value) {
var pass = Number.isInteger(value)
if (pass) {
return true;
}
return 'Please enter a valid tour ID';
}
},
];
const answers = await inquirer.prompt(prompts);
return answers.value;
};
const main = async () => {
const tourId = await getTourId();
const answers = {
tourId,
}
console.log(answers);
};
main(); |
quick fix, just change the type to "input" and validate const getTourId = async (inputs = []) => {
const prompts = [
{
type: 'input',
name: 'value',
message: 'Tour Id?',
validate: function(value) {
var pass = !isNaN(value)
if (pass) {
return true
}
return 'Please enter a valid tour ID'
},
},
]
const answers = await inquirer.prompt(prompts)
return answers.value
} |
@letanure I've just got the same error and ended up doing the same as you said => Switching from However, your {
value: '150'
} instead of {
value: 150
} So it is necessary to cast manually the values to have numbers when the prompt is done. Because I tried |
I just ran into this problem too. I couldn't delete it, but i could get rid of it via the |
As @SBoudrias mentioned, the issue is that after the validation fails, the user input is still NaN therefore will cause the error prompt to show again. NaN input => show error => input is still NaN => show error => repeat. My fix was to filter the input and return string if input is NaN.
|
This is a pretty major bug IMHO that will bite any user that types anything other than a number in response. Would be great if this could be addressed since its been open so long. The only solution seems to be to not use the 'number' type. |
Whats the tentative timeline for this issue , when will this be picked. The issue is been open for more than 4 years. |
A possible approach--> The problem users are facing is that sometimes by mistake user presses some other non number key and presses enter it gives |
When input an invalid value like
10
or'test'
, I couldn't delete it in the command line.I think it should return as a string type.But I can't pass the ci/pr.The text was updated successfully, but these errors were encountered: