1 (edited by kvvaradha 05/20/2019 05:39:55 pm)

Topic: Uncaught TypeError: found[k].className.match is not a function

This error occurs, when we select items ,or customers from the drop down on the invoice page. Sometimes it comes after login. looks like a core level js issue. needs to be identified. why it comes sometimes. 

looking developers opinion to identify the issue exactly.

Full error details.

Uncaught TypeError: found[k].className.match is not a function
    at HTMLDocument.document.getElementsBySelector (behaviour.js:25)
    at Object.apply (behaviour.js:6)
    at utils.js:24
    at JsHttpRequest.req.onreadystatechange (JsHttpRequest.js:84)
    at JsHttpRequest.t._changeReadyState (JsHttpRequest.js:71)
    at JsHttpRequest.t._dataReady (JsHttpRequest.js:50)
    at Function.JsHttpRequest.dataReady (JsHttpRequest.js:88)
    at Function.JsHttpRequest._tmp (eval at xr.onreadystatechange (JsHttpRequest.js:104), <anonymous>:1:1237)
    at XMLHttpRequest.xr.onreadystatechange (JsHttpRequest.js:106)
Subscription service based on FA
HRM CRM POS batch Themes

Re: Uncaught TypeError: found[k].className.match is not a function

Use the non-minified version of the js file and debug it.
See:
https://stackoverflow.com/questions/16266440/typeerror-match-is-not-a-function
https://stackoverflow.com/questions/38557550/uncaught-typeerror-function-is-not-a-function

Re: Uncaught TypeError: found[k].className.match is not a function

How can I reproduce this error?

www.boxygen.pk

Re: Uncaught TypeError: found[k].className.match is not a function

kvvaradha wrote:

Full error details.

Uncaught TypeError: found[k].className.match is not a function
    at HTMLDocument.document.getElementsBySelector (behaviour.js:25)
    at Object.apply (behaviour.js:6)

From the stack trace it looks like in the implementation of getElementsBySelector (behaviour.js:164) the property "className" is not guaranteed to be a string.  If it was a String, then "match" would exist. 

        if (found[k].className && found[k].className.match(new RegExp('\\b'+className+'\\b'))) {
          currentContext[currentContextIndex++] = found[k];
        }

According to MDN there are some cases where className may not be a string.
https://developer.mozilla.org/en-US/doc … /className

A reasonable check for string to use would be

Object.prototype.toString.call(found[k].className) === '[object String]'

There is likely some other error that is causing there to be a non-string DOM element in the className list on the given selector which shouldn't be there.  However, this javascript code should be protected from the error anyway.

Cambell https://github.com/cambell-prince

Re: Uncaught TypeError: found[k].className.match is not a function

I have experienced the same error. As @Cambell said, there are some cases where className may not be a string e.g an SVGSVGElement. This is happening to me when am am developing a theme that uses SVG Elements.
I suggest change of varriable "found[k].className" to "found[k].getAttribute('class')" as shown below:

Line 164 change from:

if (found[k].className && found[k].className.match(new RegExp('\\b'+className+'\\b'))) {

To

if (found[k].getAttribute("class") != null && found[k].getAttribute("class").match(new RegExp('\\b'+className+'\\b'))) { 

Please consider this fix

6 (edited by anoopmb 02/23/2021 06:51:21 am)

Re: Uncaught TypeError: found[k].className.match is not a function

This issue probably happens when using jquery and its conflict match in jquery

Another fix is to change match with test

if (found[k].className && new RegExp('\\b'+className+'\\b').test(found[k].className)) {
     currentContext[currentContextIndex++] = found[k];
}

like this

Note: match returns array or null but test returns boolean true or false

Also need to clear the cache to take effect new change

ANOOP
Experience is the name everyone gives to their mistakes!

Re: Uncaught TypeError: found[k].className.match is not a function

@joe: ?

Re: Uncaught TypeError: found[k].className.match is not a function

I have asked Janusz to look into this item. Hopefully he will respond asap.

Joe.

Re: Uncaught TypeError: found[k].className.match is not a function

Yes, while I have not found the issue on standard themes, this can be a problem when SVG element are used.
Thank you for investigating the issue, I have pushed the fix to FA repo.
J.