Turn off form and entity validation for ajax calls or at least make this possible

Created on 23 February 2016, almost 9 years ago
Updated 15 October 2023, about 1 year ago

Problem/Motivation

At the moment when you execute an ajax call and haven't set #validate the form validation will be executed, for that to happen the entity will be built first based on the current user input. This means each time you add an item to a multiple field the entity will be built and validated. In WidgetBase we set #limit_validation_errors so the form array will not be completely validated, but only the field part of it, for which a new item has been added.
Lets say you add 10 items per ajax and submit the form, what happens is that the entity is built and validated not just once but 10+1 times for each "item add" and for the final form submission, which is unnecessary and on big forms might have a performance impact.

Proposed resolution

Make it possible to turn off form validation on ajax calls. At the moment to skip the form validation you need to simply set #validate and in this case only the validation handlers set in #validate will be executed, otherwise the form #validate will be used. However atm we cannot set #validate as an empty array. For this to work we have to make couple of adjustments in the FormValidator and in FormState, so that if #validate is set and even as an empty array then use the validation handlers from it.
Additionally set '#validate' => [] on the add_more submit in WidgetBase.

Remaining tasks

Review.

User interface changes

None.

API changes

Setting '#validate' even as an empty array will turn the form validation for ajax calls.

Data model changes

None.

✨ Feature request
Status

Needs work

Version

11.0 πŸ”₯

Component
FormΒ  β†’

Last updated about 21 hours ago

Created by

πŸ‡©πŸ‡ͺGermany hchonov πŸ‡ͺπŸ‡ΊπŸ‡©πŸ‡ͺπŸ‡§πŸ‡¬

Live updates comments and jobs are added and updated live.
  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024