Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/elements/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class DatePrompt extends Prompt {
}

async validate() {
let valid = await this.validator(this.value);
let valid = await this.validator(this.value, this.answers);
if (typeof valid === 'string') {
this.errorMsg = valid;
valid = false;
Expand Down
2 changes: 1 addition & 1 deletion lib/elements/number.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class NumberPrompt extends Prompt {
}

async validate() {
let valid = await this.validator(this.value);
let valid = await this.validator(this.value, this.answers);
if (typeof valid === `string`) {
this.errorMsg = valid;
valid = false;
Expand Down
1 change: 1 addition & 0 deletions lib/elements/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Prompt extends EventEmitter {
constructor(opts={}) {
super();

this.answers = opts.answers || {};
this.firstRender = true;
this.in = opts.stdin || process.stdin;
this.out = opts.stdout || process.stdout;
Expand Down
4 changes: 2 additions & 2 deletions lib/elements/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class TextPrompt extends Prompt {
}

async validate() {
let valid = await this.validator(this.value);
let valid = await this.validator(this.value, this.answers);
if (typeof valid === `string`) {
this.errorMsg = valid;
valid = false;
Expand Down Expand Up @@ -205,4 +205,4 @@ class TextPrompt extends Prompt {
}
}

module.exports = TextPrompt;
module.exports = TextPrompt;
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function prompt(questions=[], { onSubmit=noop, onCancel=noop }={}) {
let answer, question, quit, name, type, lastPrompt;

const getFormattedAnswer = async (question, answer, skipValidation = false) => {
if (!skipValidation && question.validate && question.validate(answer) !== true) {
if (!skipValidation && question.validate && question.validate(answer, answers) !== true) {
return;
}
return question.format ? await question.format(answer, answers) : answer
Expand Down Expand Up @@ -65,7 +65,7 @@ async function prompt(questions=[], { onSubmit=noop, onCancel=noop }={}) {

try {
// Get the injected answer if there is one or prompt the user
answer = prompt._injected ? getInjectedAnswer(prompt._injected, question.initial) : await prompts[type](question);
answer = prompt._injected ? getInjectedAnswer(prompt._injected, question.initial) : await prompts[type]({ ...question, answers });
answers[name] = answer = await getFormattedAnswer(question, answer, true);
quit = await onSubmit(question, answer, answers);
} catch (err) {
Expand Down