Strange behaviour when switching delete and update product in cart view

Started by kratzi, February 14, 2016, 15:40:10 PM

Previous topic - Next topic

kratzi

Hi I am testing on VM 3.0.12 and J. 3.4.8

I regarded a strange behaviour in cart view when you switch the two buttons in cart -> default_pricelist.php

I am speaking about this code.

<input type="text"
                   onblur="Virtuemart.checkQuantity(this,<?php echo $step?>,'<?php echo vmText::('COM_VIRTUEMART_WRONG_AMOUNT_ADDED',true)?>');"
                   onclick="Virtuemart.checkQuantity(this,<?php echo $step?>,'<?php echo vmText::('COM_VIRTUEMART_WRONG_AMOUNT_ADDED',true)?>');"
                   onchange="Virtuemart.checkQuantity(this,<?php echo $step?>,'<?php echo vmText::('COM_VIRTUEMART_WRONG_AMOUNT_ADDED',true)?>');"
                   onsubmit="Virtuemart.checkQuantity(this,<?php echo $step?>,'<?php echo vmText::('COM_VIRTUEMART_WRONG_AMOUNT_ADDED',true)?>');"
                   title="<?php echo  vmText::_('COM_VIRTUEMART_CART_UPDATE'?>" class="quantity-input js-recalculate" size="3" maxlength="4" name="quantity[<?php echo $pkey?>]" value="<?php echo $prow->quantity ?>" />

<button type="submit" class="vmicon vm2-add_quantity_cart sprite" name="updatecart.<?php echo $pkey ?>" title="<?php echo  vmText::('COM_VIRTUEMART_CART_UPDATE'?>" ></button>

<button type="submit" class="vmicon vm2-remove_from_cart" name="delete.<?php echo $pkey ?>" title="<?php echo vmText::('COM_VIRTUEMART_CART_DELETE'?>" ><?php echo vmText::('COM_VIRTUEMART_CART_DELETE'?></button>


When you switch the two buttons like this or whenever the delete button is earlier in code than the update button and you enter a different number for a product in your cart and hit "enter"/"return" the product is updated but the first product in the cart also deleted.

<button type="submit" class="vmicon vm2-remove_from_cart" name="delete.<?php echo $pkey ?>" title="<?php echo vmText::('COM_VIRTUEMART_CART_DELETE'?>" ><?php echo vmText::('COM_VIRTUEMART_CART_DELETE'?></button>
<button type="submit" class="vmicon vm2-add_quantity_cart sprite" name="updatecart.<?php echo $pkey ?>" title="<?php echo  vmText::('COM_VIRTUEMART_CART_UPDATE'?>" ></button>



I was reading quite a bit about that and only one hit "enter"/"return" should never be able to execute 2 functions.
In case you use the mouse it works normal.

Regards

Spiros Petrakis

Hi Kratzi,

this is not a "bug" it is standard browser behavior , when you have an input field focused in a form and you hit enter the browser finds the first submit button in the form and executes a click.
This is called Implicit submission you can read the html specs for more details https://html.spec.whatwg.org/multipage/forms.html#implicit-submission.

For your scenario to work you need to position the button with css instead of changing the actual order of the in the file.
Joomla templates and extensions development
https://www.yourgeek.gr