Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
When creating an order using the admin UI, if the order contains required fields (such as "Terms of Use"), adding a line item is prevented by validation error.
I think of it as only a minor issue, as we can clearly check the tick-box, but still, it does not seem to be a good UX practice ;-)
Comments
Comment #1
rszrama CreditAttribution: rszrama commentedI tried to apply a quick fix by adding #limit_validation_errors to the action buttons in the line item manager widget form. This should have worked, but it isn't. I don't know why yet.
Comment #2
Simon Georges CreditAttribution: Simon Georges commentedI had the same reaction, and as the quick fix didn't work, I posted the issue, thinking you'll be better equipped to fully fix it. Sorry about that ;-)
Comment #3
rszrama CreditAttribution: rszrama commentedhehe No worries, I love a challenge. : P
Comment #4
rszrama CreditAttribution: rszrama commentedWell, I was able to get to the bottom of this. The idea is that a submit element type defaults #executes_submit_callback to TRUE, indicating that clicking the submit results in a form level submission. The form validation process checks this value and decides the form has been submitted unless the submit element specifies its own #submit callback(s). However, the button element type defaults #executes_submit_callback to FALSE, indicating that a click of that button isn't considered a form submission.
The difference is that #limit_validation_errors will be completely ignored if the form validation process decides the form is being submitted. This has worked by accident for the checkout form where we limit validation errors, because we always had a #submit callback for those buttons. However, for the line item manager widget, we don't have #submit callbacks, so changing these to button elements will be sufficient for our #limit_validation_errors values to be respected. : )
For the "Add line item" and "Save" buttons, we still validate child elements in the line item manager widget.
Commit: http://drupalcode.org/project/commerce.git/commitdiff/c825f26
Comment #5
Simon Georges CreditAttribution: Simon Georges commentedWow, nice catch! This should be documented somewhere on the Form APi, don't you think (or is it already?)?
Comment #6
rszrama CreditAttribution: rszrama commentedIt kind of is. There's an italicized remark that #limit_validation_errors will be ignored if #submit isn't set on the element, but what it doesn't say is that this is only true in the case of submit elements, not button elements.