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

setCustomValidity for checkoxes #17672

Closed
andrii-pukhalevych opened this issue Apr 21, 2024 · 2 comments
Closed

setCustomValidity for checkoxes #17672

andrii-pukhalevych opened this issue Apr 21, 2024 · 2 comments

Comments

@andrii-pukhalevych
Copy link
Contributor

Description

FormHelper generates the same oninvalid code for text inputs and checkoxes:
this.setCustomValidity(''); if (!this.value) this.setCustomValidity(this.dataset.validityMessage)

In case of checkboxes, !this.value is always false, because it can be true only if checkbox value="".
Condition should be !this.checked instead - this will allow to show custom error message for unchecked required checkbox.

CakePHP Version

4.5.4, 5.0

PHP Version

No response

@andrii-pukhalevych
Copy link
Contributor Author

In cakephp 3 condition was !this.validity.valid.
Not sure why it was changed. Maybe because another types of validation were added, like invalid email format or min/max values etc.

@othercorey othercorey added this to the 5.0.8 milestone Apr 22, 2024
@markstory markstory modified the milestones: 5.0.8, 5.0.9 May 11, 2024
@markstory
Copy link
Member

The behavior was changed back in #13499

markstory added a commit that referenced this issue May 12, 2024
Use `this.checked` instead of `this.value` for checkboxes as
we want to validate that checkboxes are checked as their value is fixed.

Fixes #17672
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants