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

Feat (checkbox): Support validate config #1319

Merged

Conversation

Srenky
Copy link
Contributor

@Srenky Srenky commented Oct 18, 2023

Second part of #1257

Added two new optional properties to config: minChoices, maxChoices

With these properties, users can specify how many choices can be selected.

The validation logic has been expanded.

image image

Possible topic for discussion

  • case when the user wants an exact number of choices selected, one possible option would be to make minChoices and maxChoices equal and extend validation logic with one more condition and its own message
  • is this something to think about?

@SBoudrias
Copy link
Owner

Hey @Srenky, thanks for sending this PR!

I'll have to disagree on the approach taken unfortunately. Adding required felt like a very common use case, but limiting the selection amount feels like less so and I would prefer not to introduce a specific validation logic for it.

Instead, I'd prefer adding a generic validate config that can be used to implement any custom validation a user might need (prevent selection of conflicting choices, or just like you did, add validation for min/max selections, etc.)

You can see an example of a generic validate function in the input & editor prompts.

Copy link

codecov bot commented Nov 2, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Files Coverage Δ
packages/checkbox/src/index.mts 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

📢 Thoughts on this report? Let us know!

@Srenky
Copy link
Contributor Author

Srenky commented Nov 2, 2023

@SBoudrias Totally agree with you on this one. I didn't even think about using validate, but it does make sense to do it this way.

Copy link
Owner

@SBoudrias SBoudrias left a comment

Choose a reason for hiding this comment

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

Few comments, but overall this look solid! Thanks!

packages/checkbox/checkbox.test.mts Outdated Show resolved Hide resolved
packages/checkbox/src/index.mts Outdated Show resolved Hide resolved
@SBoudrias SBoudrias changed the title Checkbox validation min max selected Feat (checkbox): Support validate config Nov 7, 2023
@SBoudrias SBoudrias merged commit a0cdb89 into SBoudrias:master Nov 7, 2023
12 checks passed
@SBoudrias
Copy link
Owner

Thanks a ton for the PR! Great addition :)

@Srenky Srenky deleted the checkbox-validation-min-max-selected branch November 8, 2023 12:55
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.

None yet

2 participants