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.
Delete buttons are not supposed to trigger form validation.
However, the Delete button provided by Commerce doesn't set #limit_validation_errors, leading to possible validation errors on delete (more frequent when there are additional custom form elements in the cart).
Comment | File | Size | Author |
---|---|---|---|
#9 | 1895682-cart-delete-button-validation-9.patch | 6.14 KB | bojanz |
#7 | 1895682-cart-delete-button-validation-7.patch | 6.28 KB | jsacksick |
#6 | 1895682-cart-delete-button-validation-6.patch | 6.69 KB | bojanz |
#1 | 1895682-cart-delete-button-validation.patch | 894 bytes | bojanz |
Comments
Comment #1
bojanz CreditAttribution: bojanz commentedHere's a oneline patch.
Comment #3
rszrama CreditAttribution: rszrama commentedWhy shouldn't it trigger validation? It's a submit button on the form, and if someone changes a quantity on another line item I wouldn't want their value to be lost by removing something else in the cart. So I'd say this is by design, but if you had a rationale for the change I'd be happy to entertain it.
Obviously, if this were just a delete button at the bottom of a line item entity form, we'd want it to limit validation errors. But as just one element of many on a form, I don't see why we would. I may be misunderstanding the form, though - perhaps it's using a button level submit handler so quantity values wouldn't be saved anyways?
Comment #4
bojanz CreditAttribution: bojanz commentedExactly.
EDIT: Hm, I was wrong. Right now clicking Delete will save other quantities. However, I consider that to be wrong. If you didn't update your cart, Delete shouldn't be doing that for you.
Comment #5
rszrama CreditAttribution: rszrama commentedAhh, interesting. It's how the "Checkout" button works, too.
Comment #6
bojanz CreditAttribution: bojanz commentedHere is a smarter patch.
Effects:
1) Delete doesn't trigger validation errors. It just removes the row. Quantities are not updated.
2) Quantities are updated when one of the main buttons is clicked (Update cart, Checkout)
Comment #7
jsacksick CreditAttribution: jsacksick commentedRerolled patch against dev.
Comment #8
rszrama CreditAttribution: rszrama commentedI'm still not sure I understand this change unless we introduce #ajax functionality to allow a delete button to be clicked without other data loss on the form. My observation about this being a compound form vs. a single item form still informs my opinion here - I don't think we can expect people to only make one update related operation at a time (i.e. delete vs. a quantity change vs. whatever else someone might put in this form).
Comment #9
bojanz CreditAttribution: bojanz commentedHere's a reroll for Marketplace.
I don't have a strong argument for or against. It's just what Allison and Aaron (if I'm not mistaken) thought to be expected behavior.
Comment #10
bojanz CreditAttribution: bojanz commentedComment #11
ETENTION CreditAttribution: ETENTION commentedMy mistake. Didn't watch the debug data close enough and got mixed up with another module.
And this patch seems to work.
Comment #12
kentr CreditAttribution: kentr as a volunteer commented+1 for some change to this behavior.
My use-case is:
Checkout form (at
checkout/<order-num>/checkout
) with aDelete
button and noQuantity
column in the line items. Only 1 of any item can be purchased, soQuantity
isn't applicable.Clicking
Delete
causes the form to throw validation errors b/c the billing information is empty.Comment #13
kentr CreditAttribution: kentr as a volunteer commentedFor me, looks like the
Delete
button is actually triggering form submission and checkout completion.IOW, after completing the billing information fields to sidestep the validation problem, hitting the
Delete
button submits the form, completes the checkout and purchases the item which should have been deleted.To me, that's a bug...
Regardless of whether or not the user information is lost when this button is clicked, I don't think this button should trigger checkout. There are special handlers for other buttons to avoid processing orders (
commerce_checkout_form_back_submit()
,commerce_checkout_form_cancel_submit()
) -- it seems this button needs one as well.Comment #14
kentr CreditAttribution: kentr as a volunteer commentedComment #15
bojanz CreditAttribution: bojanz at Centarro commentedYou are trying to embed a cart form into a checkout form. There's simply no way for that to work, HTML itself won't support it.
That's why you get checkout completion, Drupal is confused about which form is actually submitted.