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';
Files: 
CommentFileSizeAuthor
#4 979740-4-js_attribute_reset.patch1.71 KBdpolant
PASSED: [[SimpleTest]]: [MySQL] 3,570 pass(es).
[ View ]

Comments

Priority:Minor» Major

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

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[…]

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.

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

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

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.

Status:Reviewed & tested by the community» Needs work

Status:Reviewed & tested by the community» Needs work