For some reason, Chrome (I'm on 61.0.3163.100) auto fills the first line of the address in the coupon field.

Here's the html that's being output for me:

<input data-drupal-selector="edit-sidebar-coupon-redemption-form-code" type="text" id="edit-sidebar-coupon-redemption-form-code" name="sidebar[coupon_redemption][form][code]" value="" size="60" maxlength="128" class="form-text">
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ryross created an issue. See original summary.

joekers’s picture

We've got this issue too. Adding autocomplete="off" to the end of the <form> element seems to fix it but I'm not happy with it - I'm keen to find a better solution.

ryross’s picture

I've done a little bit more testing. If we change the element name in docroot/modules/contrib/commerce/modules/promotion/src/Element/CouponRedemptionForm.php

from
$element['code'] = [
'#type' => 'textfield',
'#title' => $element['#title'],
'#description' => $element['#description'],
'#access' => !$cardinality_reached,
];

to

$element['couponcode'] = [
'#type' => 'textfield',
'#title' => $element['#title'],
'#description' => $element['#description'],
'#access' => !$cardinality_reached,
];

then it doesn't autofill. It's triggered on 'code'. I can't seem to find why though. Here's a list of regex strings that Chrome uses:
https://cs.chromium.org/chromium/src/components/autofill/core/common/autofill_regex_constants.cc?gsn=kAddressLinesExtraRe&l=32

ryross’s picture

I'm uploading a patch that sets autocomplete to 'new-password'.

ryross’s picture

FileSize
711 bytes

Fixing the comment style

ryross’s picture

Here's some background information on autofilling with Chrome: https://bugs.chromium.org/p/chromium/issues/detail?id=468153

bojanz’s picture

Status: Active » Needs review

Houston, we have a patch.

bojanz’s picture

+      '#attributes' => array(
+        // Chrome autofills this field with the address line. We don't want that.
+        'autocomplete' => 'new-password'
+      ),

We only use [], never array(). That's old syntax.

I'll fix this on commit.

  • bojanz committed e6deea1 on 8.x-2.x authored by ryross
    Issue #2921896 by ryross, bojanz: Coupon field autofills with address...
bojanz’s picture

Status: Needs review » Fixed

Thanks!

Status: Fixed » Closed (fixed)

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