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

Validate does not run #18

Open
dr-potato opened this issue Apr 24, 2014 · 6 comments
Open

Validate does not run #18

dr-potato opened this issue Apr 24, 2014 · 6 comments

Comments

@dr-potato
Copy link

In the example below the validate function does not run (I've pasted your example validation function to make sure that I'm using the correct syntax). I'm using your plugin combined with grunt-load-config (hence the module.exports). Even though any answer to the first question should return the validation error message, nothing happens.

module.exports = {
  init: {
    options: {
      questions: [
        {
          // Ftppass reminder
          config: 'config.ftpass',
          type: 'confirm',
          message: 'Is .ftppass in the root of your local project folder?',
          validate: function (value) {
            var valid = semver.valid(value) && true;
            return valid || 'Must be a valid semver, such as 1.2.3-rc1. See ' +
              'http://semver.org/'.blue.underline + ' for more details.';
          }
        },
        {
          // Set the name of the project
          config: 'config.name',
          type: 'input',
          message: 'What is the name of your project?'
        },
        {
          // Select templates to be used
          config: 'config.templates',
          type: 'checkbox',
          message: 'Which templates do you want to use?',
          choices: [
            { name: '404.php', checked: false },
            { name: 'archive.php', checked: false },
            { name: 'comments.php', checked: false },
            { name: 'footer.php', checked: true },
            { name: 'functions.php', checked: false },
            { name: 'header.php', checked: true },
            { name: 'index.php', checked: true },
            { name: 'page.php', checked: false },
            { name: 'search.php', checked: false },
            { name: 'sidebar.php', checked: false },
            { name: 'single.php', checked: false },
            { name: 'template-fullwidth.php', checked: false },
            { name: 'template-leftsidebar.php', checked: false },
            { name: 'template-twosidebar.php', checked: false }
          ]
        }
      ]
    }
  }
};
@dr-potato
Copy link
Author

I understand now that validate only works with input (or strings)? While this makes sense, maybe it's worth adding that to the docs? It took me a while to figure it out (maybe others won't have this problem, but it's still an easy thing to miss).

@wclr
Copy link

wclr commented May 24, 2014

Yes it would be good if confirm prompt result could be checked in the task (validate for example). Or there is need to create some post action that will be called for any answer.

@wclr
Copy link

wclr commented May 24, 2014

Ah there is actually a post processor "then", then this may be closed.

@dylang
Copy link
Owner

dylang commented Oct 26, 2014

sounds like this can be closed. if i was wrong let me know.

@dylang dylang closed this as completed Oct 26, 2014
@joakim
Copy link

joakim commented Feb 10, 2015

You were wrong :)

The validate and then functions don't get called for the confirm type. The maintainer of Inquirer.js doesn't think that warrants a fix, and suggests that it is handled by grunt-prompt.

See SBoudrias/Inquirer.js#93:

They could wrap inquirer.prompt calls.

#4 is also about this issue.

@nmalacarne
Copy link

I am also having problems with this.

 ...
  prod: {
    options: {
      questions: [{
        config: 'buildControl.prod',
        type: 'confirm',
        message: 'Are you SURE you want to deploy to PRODUCTION?',
        default: false,
        validate: function (value) { return false; }
      }]
    }
  }
...

The task chain always completes regardless of the answer to the prompt. Am I misunderstanding this functionality?

@dylang dylang reopened this Apr 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants