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

Initial value not passed to validate function for "number" types #410

Open
ryangoree opened this issue Dec 17, 2023 · 0 comments
Open

Initial value not passed to validate function for "number" types #410

ryangoree opened this issue Dec 17, 2023 · 0 comments

Comments

@ryangoree
Copy link

Describe the bug

When the type is number, the validate function doesn't receive the initial value.

So if you have a number that requires validation, the user can't accept the default.

To Reproduce

Steps to reproduce the behavior:

  1. Create a number prompt with an initial value
  2. Run and accept the default value
  3. Check the value in the validate function to see it's an empty string
import prompts from "prompts";

await prompts({
  type: "number",
  name: "value",
  message: "Enter a number",
  initial: 20,
  validate: (val) => {
    // Value will be an empty string if you accepted the default
    console.log("value", val);
    return val > 0;
  },
});

Expected behavior

The validate function would get the initial value and it would be a number.

System

  • Node version: 18.16
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

1 participant