XF 2.2 Uncaught TypeError: a.barrating is not a function

FoxSecrets

Active member
I'm racking my brain over this error and I still haven't figured it out!

It happens when I click on "Leave a rating" on any XFRM resource, but JUST when my add-on is installed.
When I uninstall my add-on, the button works again as usual.

This is very strange because my add-on is unrelated to XFRM so I have no idea what is going on.
I don't know if it's a XF bug or something caused by my add-on.

How to solve it? Does anyone have an idea? My XF version is 2.2.8 and XFRM 2.2.4
EDIT: I inserted the script but the error persists
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-bar-rating/1.2.2/jquery.barrating.min.js" referrerpolicy="no-referrer"></script>

Code:
rating-compiled.js?_v=c95a5dd5:3 Uncaught TypeError: a.barrating is not a function
    at c.init (rating-compiled.js?_v=c95a5dd5:3:327)
    at b (core-compiled.js?_v=c95a5dd5:150:237)
    at c (core-compiled.js?_v=c95a5dd5:150:427)
    at HTMLSelectElement.<anonymous> (core-compiled.js?_v=c95a5dd5:151:75)
    at Function.each (jquery-3.5.1.min.js?_v=c95a5dd5:2:2976)
    at S.fn.init.each (jquery-3.5.1.min.js?_v=c95a5dd5:2:1454)
    at Object.f [as initialize] (core-compiled.js?_v=c95a5dd5:151:59)
    at Object.activate (core-compiled.js?_v=c95a5dd5:43:175)
    at b.__construct (core-compiled.js?_v=c95a5dd5:113:448)
    at new b (core-compiled.js?_v=c95a5dd5:76:174)
 
Last edited:
XF already includes the jQuery barrating plugin in 2.2. Does your add-on include any JS on the resource pages?
 
Not yet, because I don't know what the issue is.

Does your add-on include any JS at all, whether seemingly relevant or not, globally or specifically on the resource pages?
 
Yes it includes JS, but not related to resources page.
About the jquery, you mean twice from my add-on ? or it already exists in XF?
 
Yes, I commented all jquery calls and now it worked! Thanks @Jeremy P
It was really loading twice <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
 
Last edited:
@Jeremy P, after solving this problem, another one related to it appeared

After removing the jquery the error 'barrating' in rating button has gone, but now the responses to posts are not working accordingly. If I put back the jquery, the posts work but the 'barrating' error comes up again.

How to solve that?

Without jquery (page reload needed):
error-without-jquery.gif


With jquery (ok):
error-with-jquery.gif
 
Not sure off-hand. As usual, you can try with a default style or disabling add-ons and re-enabling one by one to narrow in on a cause.

It might also be worth checking the browser console for errors. You may have to enable the 'Preserve log' option to retain them between page reloads.
 
The errors come also from my add-on. If I uninstall it, all works well.

One way to avoid these errors is to insert the scripts just on my add-on, however I don't have head and body tags to modify, the only way as I know is through page container, which is global, right?

How can I insert my scripts specifically on my add-on?
 
How are they being inserted now? You can just use <xf:js> on the templates where they are required to include them.
 
Yes I usually do this way, but I mean, some of templates requires the same script, this is why I was putting under page container.

So in this case I would put on each template even repeating it, right? I don't really like that, but it's a solution.
 
Yeah. Even if both templates are on the same page, the script will only be included once. You can also abstract out the <xf:js> calls into a macro and use that instead.
 
Back
Top Bottom