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).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bojanz’s picture

Status: Active » Needs review
FileSize
894 bytes

Here's a oneline patch.

Status: Needs review » Needs work

The last submitted patch, 1895682-cart-delete-button-validation.patch, failed testing.

rszrama’s picture

Category: bug » task

Why 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?

bojanz’s picture

perhaps it's using a button level submit handler so quantity values wouldn't be saved anyways?

Exactly.

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.

rszrama’s picture

Ahh, interesting. It's how the "Checkout" button works, too.

bojanz’s picture

Status: Needs work » Needs review
FileSize
6.69 KB

Here 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)

jsacksick’s picture

Rerolled patch against dev.

rszrama’s picture

Title: The delete button in the cart should not trigger form validation » Prevent form validation / submission when a line item delete button is clicked at /cart
Category: Task » Feature request
Issue summary: View changes
Status: Needs review » Needs work

I'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).

bojanz’s picture

Here'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.

bojanz’s picture

Status: Needs work » Needs review
ETENTION’s picture

My mistake. Didn't watch the debug data close enough and got mixed up with another module.

And this patch seems to work.

kentr’s picture

+1 for some change to this behavior.

My use-case is:

Checkout form (at checkout/<order-num>/checkout) with a Delete button and no Quantity column in the line items. Only 1 of any item can be purchased, so Quantity isn't applicable.

Clicking Delete causes the form to throw validation errors b/c the billing information is empty.

kentr’s picture

For 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.

kentr’s picture

Category: Feature request » Bug report
bojanz’s picture

You 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.