Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 293938

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

$
0
0

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.


Viewing all articles
Browse latest Browse all 293938

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>