silverstripe / silverstripe-framework

Silverstripe Framework, the MVC framework that powers Silverstripe CMS
https://www.silverstripe.org
BSD 3-Clause "New" or "Revised" License
722 stars 821 forks source link

[ORM] validationExempt(true) broken for required fields #7745

Open worikgh opened 6 years ago

worikgh commented 6 years ago

Affected Version

Show version numbers by pasting the output of composer info --direct.

$ ../composer.phar info --direct phpunit/phpunit 5.7.26 The PHP Unit Testing framework. silverstripe/recipe-cms 1.0.0 SilverStripe recipe for fully featured page and asset content editing silverstripe/recipe-plugin 1.0.0 Helper plugin to install SilverStripe recipes

Hovering gets me Framework 4.0.0 and CMS 4.0.0

Description

Setting the required fields validator, then turning off validation for a action does not work.

The apparent reason is that 'RequiredFields' is implemented by writing 'required="required" into the HTML attributes of the fields. Thus the exemption from validation never gets a chance.

So it is not possible to have required fields and have a cancel button.

The solution is to have a separate form for the cancel button. Very infradig! For visual issues, please include browser version and screenshots. Please read https://docs.silverstripe.org/en/contributing/issues_and_bugs/

Steps to Reproduce

Create a form whith required fields and a cancel button. Call validationExempt(true) on the cancel button. It will not work

kinglozzer commented 6 years ago

I guess one workaround would be to add $form->setAttribute('novalidate', true);.

That might need to be part of the fix too - I don’t see how else we can solve this without removing the required attribute from fields...

dhensby commented 6 years ago

https://stackoverflow.com/a/18202812/4978044

kinglozzer commented 6 years ago
tractorcow commented 6 years ago

Wow that's great :D