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.
This is verbatim from our sprint discussion notes...
Investigate: Instead of storing checkout pane validate handlers in $form['#validate'], store them in the fieldset's $form['pane']]['#pane_validate'] array. In the submit step, run the validation for each fieldset and then process the submit handlers for any panes that pass validation. This allows the form to be rebuilt if part of it fails validation. The problem might be, though, that we need to then repopulate fields on the form with the invalid values when we rebuild it... and we don't know where the invalid values would come from. : )
Comment | File | Size | Author |
---|---|---|---|
#16 | 842292-16.checkout_validate.patch | 4.51 KB | rszrama |
#12 | 842292-12.checkout_validate.patch | 4.52 KB | rszrama |
#9 | 842292-9.checkout_validate.patch | 3.8 KB | rszrama |
#7 | commerce-validate-pane.png | 27.13 KB | Damien Tournoud |
#6 | 842292-checkout-form-validation.patch | 3.58 KB | Damien Tournoud |
Comments
Comment #1
rszrama CreditAttribution: rszrama commentedI believe Damien has done this, but we still need to implement the AJAX loading of the same page...
Comment #2
rszrama CreditAttribution: rszrama commentedLet's decide if this needs to happen for RC1, too. We've survived so long without it that I'm not sure it's necessary...
Comment #3
Damien Tournoud CreditAttribution: Damien Tournoud commentedWe are nearly there. There is actually one small change necessary here: when a form fails validation (for example because a required element is not present) no pane are processed.
Fixing this looks easy, see the 7.x-1.x-842292 branch.
Comment #4
rszrama CreditAttribution: rszrama commentedCross linking a duplicate issue: #1289014: Custom checkout pane custom form validation expects abnormal validation behavior
Comment #5
Damien Tournoud CreditAttribution: Damien Tournoud commentedComment #6
Damien Tournoud CreditAttribution: Damien Tournoud commentedHere is a reroll.
Comment #7
Damien Tournoud CreditAttribution: Damien Tournoud commentedThis patch moves the pane validation / submit logic from a form submit where it currently lies to a form validate.
This allow us to properly validate and submit panes independently one from the other. One visible change for this is that error messages related to required fields are now properly showing attached to every pane:
Comment #9
rszrama CreditAttribution: rszrama commentedI've attached an update that'll pass the testbot (conflict with the recently committed patch to fix messages in checkout). I also brought back the submit handler to actually handle message restoring between page redirects and to set the redirect URL. This code came after an if check in the old handler that required validation to pass... so it was basically the actual submission part of the old submit handler.
The only thing I don't know is if you'd want me to clear the submit handlers at the end of the checkout form builder function like you do for the validate handlers. Interested to see what the test bost says. My local tests all worked great.
Comment #11
rszrama CreditAttribution: rszrama commentedJust a note to say that I'm debugging those fails; as far as I can tell, they're related to the fact that making validation actually happen in a validation handler now means we have to accommodate AJAX posts which, in the case of the failing test, only includes an update to a country. If this is changed on the same page as an invalid e-mail address, we don't have the proper contents in the messages array in the form state for the pane.
Comment #12
rszrama CreditAttribution: rszrama commentedAlrighty, what was happening was this code was replacing the stored messages array with rendered HTML at a time when that stored messages array would still need to be accessed again in a subsequent AJAX validation in which the previous errors are still present:
It could be we don't need to store the themed output in the form state or even that we could work some bypass into this during AJAX validation, but I'm trying to preserve the intent of the original patch by just putting the themed output in a separate 'themed_messages' array.
Also, I went ahead and set the form level #submit handlers like you did for #validate.
All clear, test bot and Damien bot?
Comment #14
rszrama CreditAttribution: rszrama commented#12: 842292-12.checkout_validate.patch queued for re-testing.
Comment #16
rszrama CreditAttribution: rszrama commentedTest bot is out of disk space. Just as well since I had a typo. :-/
Comment #17
rszrama CreditAttribution: rszrama commentedIn case that fails provisioning again, this passed testing locally. If I don't hear any negative feedback, I'll commit this later today. It doesn't change any logic from your original patch that I can see and simply moves the submit handlery type stuff into a legit submit handler.
Comment #18
rszrama CreditAttribution: rszrama commentedCommit: http://drupalcode.org/project/commerce.git/commitdiff/0e0beff