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

Prompt validation does not visualize the output (errors) #69

Open
sanderhouttekier opened this issue Dec 23, 2015 · 7 comments
Open

Prompt validation does not visualize the output (errors) #69

sanderhouttekier opened this issue Dec 23, 2015 · 7 comments

Comments

@sanderhouttekier
Copy link

using inquirer a prompt with validate function should show the validate output, but with vorpal it is somehow omitted.

this.prompt([
    {
        type: 'input',
        name: 'test',
        message: 'Please type something different than `test` to see an error pop up... or type `test` to continue',
        validate: function (val) {
            if (val != 'test') {
                return "Please answer with the word test";
            }
            return true;
        }
    }
], function(answers) {
    console.log(answers);
});

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.

@jackyjieliu
Copy link
Contributor

throw the error instead of returning it

validate: function (val) {
  if (val != 'test') {
      throw "Please answer with the word test";
  }
}
@sanderhouttekier
Copy link
Author

@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";
      }
    }
  }
// ...
@dthree
Copy link
Owner

dthree commented Dec 27, 2015

Got it. Will check out as soon as I can!

@sarcadass
Copy link

I've got the same problem here,

@scotthovestadt
Copy link
Contributor

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.

@dthree
Copy link
Owner

dthree commented Jan 31, 2016

Yes, that's correct.

@marcos-abreu
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment