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

Multi Prompt #107

Closed
macmichael01 opened this issue Jan 12, 2019 · 2 comments
Closed

Multi Prompt #107

macmichael01 opened this issue Jan 12, 2019 · 2 comments
Labels

Comments

@macmichael01
Copy link

It would be nice to have a multi prompt similar in some ways to the form prompt but with a couple minor differences.

First, render the actual registered prompts for validation purposes. (which I don't think forms supports that but might be nice if it did too).

Second, the purpose of multi prompt is to re-ask the same questions over until the user indicates they are finished. This would be great for populating an array of objects.

E.g -
Contributors:

  • Full Name:
  • Email:
  • Website:
    Would you like to add another (Y/n)?

The end result might look something like the following:

{
  contributors: [{
    full_name: "jon",
    email: 'jon@enquirer.com',
    website: 'enquirer.com'
  },{
    full_name: "jon",
    email: 'jon@enquirer.com',
    website: 'enquirer.com'
  }]
}
@jonschlinkert
Copy link
Member

@macmichael01 I think both of your requests possible now.

Request 1 - Validating form choices

The Form prompt supports validation. If you aren't able to get it working, then please create a bug report so we can see what's causing problems for you and get it fixed. See this example.

In the choice objects, you can add a validate() function.

Request 2 - Re-asking the same questions

You should be able to accomplish this by simply wrapping your prompt in a function, and recursively calling the function if the user gives a truthy response. Let us know if you have trouble getting this to work. If I'm not understanding your request, then it might help to provide a more detailed example, possible a mockup of the screen so that I can visualize what you mean (I'm a visual learner, and I have a much harder time understanding verbally. Thanks in advance!)

@jonschlinkert
Copy link
Member

Closing based on age and lack of response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants