SBoudrias/Inquirer.js

Use value from list prompt in message for next question?

paul-uz opened this issue · 3 comments

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?

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: [...]
});

I'm using inquirer.prompt()

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} ...`, ... }
]);