Problem/Motivation

Our project concerned an online shop with the possibilities to add products to favorites.
When we use Flag module to handle favorites for our project, an error occured when the page is loaded or when we tried to add our product to favorites with IE11.

'SCRIPT438:Object doesn't support property or method 'forEach'

This error is caused by the 12th line of flag-action_link_flash.js script.

Proposed resolution

Change "forEach" method with $.each() one.

Before:

links.forEach(function (link) {
        return link.addEventListener('click', function (event) {
          return event.target.parentNode.classList.add('flag-waiting');
        });
      });

After:

$.each(links, function (key, link) {
        return link.addEventListener('click', function (event) {
          return event.target.parentNode.classList.add('flag-waiting');
        });
      });

Remaining tasks

Create a patch with this correction and review it with flag community.

Comments

AnaSwin created an issue. See original summary.

AnaSwin’s picture

StatusFileSize
new555 bytes
gerson.analista’s picture

I had the same problem, I applied the patch #2, but didn't solve the problem.

I made a small change and generated a new patch.

gerson.analista’s picture

Status: Active » Needs review
martin107’s picture

Just providing context

https://caniuse.com/#search=forEach

When I checked today

ie11 is not suported
and has a global use of 1.39%

ericgsmith’s picture

StatusFileSize
new4.02 KB

Looks like the flag module uses core's js transpile workflow to manage JS so we need to fix the source files rather than the transpiled output.

In doing so - it looks like when the admin file was committed, it wasn't generated, so I've made a small change so that it matches the output.

Note - nodelist.forEach is not supported in ie11, array.forEach is - so I've followed a standard way to convert the node list object to an array.

martin107’s picture

Status: Needs review » Reviewed & tested by the community

so I've followed a standard way to convert the node list object to an array.

All changes to .es6.js files look OK

and the corresponding transpiled output look good as well.

ericgsmith -- That is a nice touch. Thank you.

  • Berdir committed a70d670 on 8.x-4.x authored by ericgsmith
    Issue #3043397 by AnaSwin, gerson.analista, ericgsmith: ForEach not...
berdir’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, committed. JS is mostly a blackbox for me, so just going to believe you that this fixes the problem ;)

berdir’s picture

Status: Fixed » Closed (fixed)

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