Skip to content

fix: validate initial values #316

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

Merged
merged 2 commits into from
May 13, 2025
Merged

fix: validate initial values #316

merged 2 commits into from
May 13, 2025

Conversation

dreyfus92
Copy link
Member

@dreyfus92 dreyfus92 commented May 13, 2025

When using text prompts with initialValue and validate props, validation was not being triggered for incorrect initial values. Users had to press enter first to see validation messages.

This fix:

  • Validates initial values as soon as they are set
  • Shows validation messages immediately for invalid initial values
  • Maintains the prompt in error state until a valid value is entered

Added a couple of tests and an example.

Closes: #315

Copy link

changeset-bot bot commented May 13, 2025

🦋 Changeset detected

Latest commit: 5bbdb56

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@clack/core Patch
@clack/prompts Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

pkg-pr-new bot commented May 13, 2025

@example/basic@example/changesets

npm i https://pkg.pr.new/bombshell-dev/clack/@clack/core@316
npm i https://pkg.pr.new/bombshell-dev/clack/@clack/prompts@316

commit: 5bbdb56

Copy link
Collaborator

@43081j 43081j left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks good to me

loosely related, i do wonder if we should have some kind of "validate on key press" option one day. currently, we will validate when you press <return> and not when you're typing. this PR conflicts with that since the user hasn't pressed return yet, but does make the UX nicer ofc.

@MacFJA
Copy link
Contributor

MacFJA commented May 13, 2025

loosely related, i do wonder if we should have some kind of "validate on key press" option one day. currently, we will validate when you press <return> and not when you're typing. this PR conflicts with that since the user hasn't pressed return yet, but does make the UX nicer ofc.

I made a change in this direction in #240

@dreyfus92 dreyfus92 merged commit 34f52fe into main May 13, 2025
6 checks passed
@dreyfus92 dreyfus92 deleted the fix/validation-issue branch May 13, 2025 14:17
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

Successfully merging this pull request may close these issues.

[Bug] validation not triggered when using initialValue
3 participants