Open sanderhouttekier opened 8 years ago
throw the error instead of returning it
validate: function (val) {
if (val != 'test') {
throw "Please answer with the word test";
}
}
@jackyjieliu will try, however I doubt that's going to be the issue, I'm positive that it is vorpal who surpresses the errors, since inquirer.js (used by vorpal) tells us to do it by returning an errorMessage.
see the third input in their examples. https://github.com/SBoudrias/Inquirer.js/blob/master/examples/input.js
// ...
{
type: "input",
name: "phone",
message: "What's your phone number",
validate: function( value ) {
var pass = value.match(/^([01]{1})?[\-\.\s]?\(?(\d{3})\)?[\-\.\s]?(\d{3})[\-\.\s]?(\d{4})\s?((?:#|ext\.?\s?|x\.?\s?){1}(?:\d+)?)?$/i);
if (pass) {
return true;
} else {
return "Please enter a valid phone number";
}
}
}
// ...
Got it. Will check out as soon as I can!
I've got the same problem here,
This is a tough one since Vorpal has completely taken over rendering, so it'll probably also have to take over looking for the validate parameter, calling it, and rendering the output.
Yes, that's correct.
I've just created a PR that hopefully fix the issue. I've tested in one project I'm working and it fixes the issue on the 3 instances I'm validating.
using inquirer a prompt with validate function should show the validate output, but with vorpal it is somehow omitted.
in Inquirer you can see this work perfectly in the
examples/input.js
example. however the error gets lost somewhere in the process within vorpal I assume.