cakephp / cakephp

CakePHP: The Rapid Development Framework for PHP - Official Repository
http://cakephp.org
MIT License
8.68k stars 3.44k forks source link

setCustomValidity for checkoxes #17672

Closed andrii-pukhalevych closed 1 month ago

andrii-pukhalevych commented 2 months ago

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 commented 2 months ago

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.

markstory commented 1 month ago

The behavior was changed back in https://github.com/cakephp/cakephp/pull/13499