Closed tjbenton closed 7 years ago
For someone that comes across this and this feature hasn't been merged yet you can do the same thing without installing my specific package by doing the following. Hope this helps.
import inquirer from 'inquirer'
import autocomplete from 'inquirer-autocomplete-prompt'
const originalRun = autocomplete.prototype._run
autocomplete.prototype._run = function Run(cb) {
originalRun.call(this, cb)
if (!!this.opt.initial) {
// emit a keypress event to pass in the initial option
this.rl.input.emit('keypress', this.opt.initial) // trigger the search
}
}
inquirer.registerPrompt('autocomplete', autocomplete)
It's better handled in the source parameter. Like this:
inquirer.prompt([{
type: 'autocomplete',
name: 'from',
message: 'Select a state to travel from',
source: function(answersSoFar, input) {
input = input === null ? 'Alabama': input;
return myApi.searchStates(input);
}
}])
@mokkabonna My use case is to pre-fill the prompt and allow user changing it, so I've used @tjbenton 's patching approach for now, but if it's still up for consideration, I would vote for adding this feature in the library itself
This adds the ability to pass in an initial value to search for. This should solve #18
To see how this would work you can pull this branch down run
node example.js 'k.*' 'c.*'