Probably too late for D7, but filing as a feature request for D8.

D7 introduced #limit_validation_errors so that AJAX/multistep interactions are not cluttered with validation errors on parts of the form not involved in the step. The property points a subpart of the $form array, for which validation is performed - validation is skipped for the rest of the form.
In a followup, #763376: Not validated form values appear in $form_state pushed the effect much further : if #limit_validation_errors is used, then only the elements in the $form subpart show up in $form_state['values'].

This API is fine for the primary use case this was introduced for : "add more" buttons, which shouldn't be blocked on "node title is required".

A different pattern, found on Field UI's "Manage display" is : display a subform (formatter settings), with 'Submit' and 'Cancel' buttons relevant to that subform - the 'Cancel' button should skip validation within the subform.
Using #limit_validation_errors is tricky here, because it would require we explicitly specify 'the rest of the form' (without the subform) - really difficult, and completely unfriendly for modules altering the form. The fact that form element not mentioned in #limit_validation_errors are hidden from $form_state['values'] makes it even worse.

What we need here is an alternate #skip_validation_errors option, that has a reversed semantics : lets you specify a part of the form where validation errors are skipped - i.e the complement of what you'd put in #limit_validation_errors.

Comments

yched’s picture

Hm, the tricky bit of course being : how would #limit_validation_errors and #skip_validation_errors coexist in the same form... :-/

rfay’s picture

yup

sun’s picture

Hm. I rather think that those "embedded field settings forms" in Field UI should be entirely separate forms; i.e., not part of the wrapping Field UI overview form. AJAX can happily submit an injected sub-form only. Having the settings form in a more atomic fashion also allows to expose it in entirely different locations (e.g., edit-in-place-alike functionality/contextual links).

yched’s picture

@sun : Hm, interesting take.

"AJAX can happily submit an injected sub-form only"
Not sure what that would look like, though. The D7 ajax framework + $form_state / rebuild behavior made a really nice match for this kind of form as Field UI currently implements it.

effulgentsia’s picture

Subscribe, though I'm also wondering why "Cancel" needs anything to be validated. Why not #limit_validation_errors => array()? With #622922: User input keeping during multistep forms, rebuilding should still preserve input values for purposes of ensuring that the HTML returned by the AJAX doesn't clear out in-progress modifications of the rest of the form. Does it make sense for a Cancel button's submit handler or form rebuilding logic to rely on anything in $form_state['values']?

I'm not opposed to something like #skip_validation_errors in D8. Just wondering how to solve the Field UI issues in D7.

yched’s picture

@eff : Yes, "Manage display" already heavily relies on #622922: User input keeping during multistep forms (which was godsend to keep iterative forms reasonably simple)

#limit_validation_errors => array() was what I originally went with in #796658: UI for field formatter settings. After #763376: Not validated form values appear in $form_state, we had to make sure that $form_state['values'] contained a minimal set of vital values in #896162: Write tests for the Field UI formatter settings form (first couple comments).
Now that you mention it, it's not clear to me either why the 'Cancel' button needed that - apparently it was clear to me when I explicitly fixed it in #896162-2: Write tests for the Field UI formatter settings form :-)

Anyway - maybe 'Cancel' is a wrong example here. The case applies to the 'Edit settings' button : needs a #limit_validation_errors without getting an empty $form_state['values'] (needs to 'cancel' any open settings form on other rows, ditching validation errors, and open the settings form for the current row and its currently selected formatter).

Don't worry about fixing Field UI forms. As is, they should be fine for D7. I just mean that with the awesome powa of D7 ajax + $form rebuilding for iterative forms, this won't be a rare pattern.

attiks’s picture

geek-merlin’s picture

sub

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Active » Postponed (maintainer needs more info)

Wonder if this is still needed for D10 with so little movement?

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.