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

Validation in Form #430

Open
KernelDeimos opened this issue Jul 24, 2023 · 2 comments
Open

Validation in Form #430

KernelDeimos opened this issue Jul 24, 2023 · 2 comments

Comments

@KernelDeimos
Copy link

Reply on #107 suggests validation works in Form prompts.

Visually, it does - the indicator changes based on whether the input is valid. However, the Form prompt doesn't re-try or throw an error on failed validation, forcing me to again validate and implement re-try manually. What I want is for the user to not be able to submit the form until it's valid.

@jonschlinkert
Copy link
Member

Can you provide more details @KernelDeimos? It would be great if you could show a basic example of the form prompt you were trying to get working, with config, choices, etc.

@micalevisk
Copy link

micalevisk commented Nov 14, 2023

@jonschlinkert here's mine:

  const prompt = new Form({
    name: 'user',
    message: 'Please provide the following information:',
    choices: [
      {
        name: 'firstname',
        message: 'First Name',
        validate(value){
          this.error = 'Invalid name'
          return false
        }
      },
    ]
  });

  prompt.run()
    .then(value => console.log('ANSWERS:', value))
    .catch(console.error)

I got:

image

although the validate always returns false, the user can press enter just fine 🤔 Am I missing something?

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

3 participants