Inquirer.js icon indicating copy to clipboard operation
Inquirer.js copied to clipboard

[Question] How can I have an input question with prefilled data?

Open brlebtag opened this issue 4 years ago • 5 comments

My problem is: I create a dynamic name based on some informations asked before and I want to check with the user if the name is good, otherwise they can fix whatever the way they want.

I'd like to do something like this:

const answers = await this.prompt([
                {
                    type: 'input',
                    name: 'fixed',
                    message: 'Ok, you can fix the name now',
                    value: nameToBeFixed
                },
            ]);

How can I do that?

Thanks in advance!

brlebtag avatar Apr 09 '20 14:04 brlebtag

Usually, you use default.

default: (String|Number|Boolean|Array|Function) Default value(s) to use if nothing is entered, or a function that returns the default value(s). If defined as a function, the first parameter will be the current inquirer session answers.

Unless you mean you want the input to be PREPOPULATED with something, so the user can backspace over it?

kschang77 avatar Apr 21 '20 03:04 kschang77

@kschang77 Do you have an example of how to pre-populate the value for an input type (editable)?

remisture avatar Jul 27 '20 16:07 remisture

I'm looking for "PREPOPULATED " too.

oom- avatar Dec 21 '20 20:12 oom-

Hello, I'm looking for a pre-populated answer too (to be editable, not default) @brlebtag did you manage it ?

Thanks

thiboot avatar Dec 22 '20 07:12 thiboot

Sorry guys. I didn't see the messages.

@kschang77 Yeah I want it to be pre-populated and the user can later edit it. So it is not just a default option.

@thiboot No, I didn't.

brlebtag avatar Dec 22 '20 12:12 brlebtag