Just came across the issue that e.g. Firefox caches the state of a select-box on a page reload.
Since the prices, displayed in my "Add to Cart" form, are attribute dependent. It's possible, that the displayed prices don't fit to the cached select-box state, after a page reload.
To prevent this confusing state, we should think about adding the HTML attribute autocomplete="off" to the whole form by default.
Code to do so:

$form['#attributes']['autocomplete'] = 'off';
#13 979740-13.add_to_cart_autocomplete.patch702 bytesrszrama
#4 979740-4-js_attribute_reset.patch1.71 KBdpolant
PASSED: [[SimpleTest]]: [MySQL] 3,570 pass(es). View
Members fund testing for the Drupal project. Drupal Association Learn more


Damien Tournoud’s picture

Priority: Minor » Major

Hm. Feels that the javascript should rather reload its state automatically.

mikl’s picture

Problem is, “autocomplete” is not a valid attribute according to the HTML specs (it may be in HTML5, but not HTML4/XHTML). Quoting the Sitepoint HTML reference on the input element:

[…]another attribute that you might come across that is IE-specific, autocomplete with values of "on" or "off"[…]it is not cross-browser safe[…]

rszrama’s picture

Ahh, I see the problem. On the demo site at http://demo.commerceguys.com/dc/catalog/wearables/looking-smiling-faces if I select X-Large and then refresh the page I get:

Drupal's #ajax system isn't setup to capture the browser reusing a previous default value without triggering some sort of JS event, so the form isn't resubmitted with the selected value to update fields on the page. Obviously server side we have no way of knowing this has happened, so we either need to 1) ensure the expected defaults are set (i.e. using autocomplete or JS) or 2) resubmit that form on reload.

I don't like either option, but I'm not sure we have a way around this... and using JS to reset the value here will not be degradable, although I'm a bit worried about general degradation anyways. ; )

By experience, though, I wonder if Sitepoint isn't outdated. I've used autocomplete fields successfully on other browsers just fine - for example, it's used in Credit Card data entry forms to ensure browsers don't cache CC numbers. I think it bears further investigation. fwiw, I didn't know about it being usable on a form element.

dpolant’s picture

1.71 KB
PASSED: [[SimpleTest]]: [MySQL] 3,570 pass(es). View

I checked recently and this is still a problem.

Here's what I've found: setting autocomplete="off" on either the form or the select/input elements does solve the problem in FF and IE. However since autocomplete is part of HTML 5, the resulting html will not validate under Drupal 7's default XHTML doctype. So although the 1 line solution is tempting, it leads to invalid markup so I would't recommend it.

The javascript reset option may be the best way to go. The attached patch stores defaults in Drupal.settings and sets the input/select values on page load if it detects that the form is not being loaded from a previous submission (i.e. user clicked refresh or hit the url directly).

mikejoconnor’s picture

Status: Needs work » Reviewed & tested by the community

I've tested this on patch on the latest version of kickstart. It works as anticipated, changing the values back to their default value when you reload the page.

Marking RTBC

esoteric1’s picture

Status: Needs work » Reviewed & tested by the community

Did not work for me. After installing that code, I can no longer make any selections. they always reload the default selections. Although I was using the 7.x-1.x installation.

esoteric1’s picture

Status: Reviewed & tested by the community » Needs work

Status: Reviewed & tested by the community » Needs work
rszrama’s picture

Issue summary: View changes
Issue tags: +sprint
joelpittet’s picture

I think the HTML attribute would be the cleaner approach and it's good on HTML5 and most current browsers:

joelpittet’s picture

@mikl time's have changed since 2012... any chance your thoughts on this have too?

vasike’s picture

+1 for autocomplete="off"

As i remember there was a similar issue for "Payments selection" in the checkout :(.

rszrama’s picture

Priority: Major » Normal
Status: Needs work » Needs review
702 bytes

Looks like we waited this one out ... patch should do it, per das-peter.

rszrama’s picture

Status: Needs review » Fixed


joelpittet’s picture

Sweet thanks @rszrama!

  • rszrama committed a3bcbd3 on 7.x-1.x
    Issue #979740 by rszrama, das-peter: disable autocompletion on the Add...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.