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

Use value from list prompt in message for next question? #1343

Closed
paul-uz opened this issue Jan 4, 2024 · 3 comments
Closed

Use value from list prompt in message for next question? #1343

paul-uz opened this issue Jan 4, 2024 · 3 comments

Comments

@paul-uz
Copy link

paul-uz commented Jan 4, 2024

I have a inquirer prompt with 2 questions, a list and then a choice. I want to use the selected value form the list in the message for the choice question.

Is this possible?

@SBoudrias
Copy link
Owner

Hi Paul, this should be possible. Here's some pseudo code showing an approach:

const answer1 = await input({ ... });

const answer2 = await select({
    message: `... ${answer1} ...`,
	choices: [...]
});

@paul-uz
Copy link
Author

paul-uz commented Jan 4, 2024

I'm using inquirer.prompt()

@SBoudrias
Copy link
Owner

It'd be the same idea, but slightly more verbose:

const { answer1 } = await inquirer.prompt([
    { name: 'answer1', ... }
]);

const { answer2 } = await inquirer.prompt([
    { name: 'answer2', message: `... ${answer1} ...`, ... }
]);

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

2 participants