Uncaught TypeError: $(...).once is not a function with Drupal 10.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mornel created an issue. See original summary.

shivam_tiwari made their first commit to this issue’s fork.

igor mashevskyi’s picture

Assigned: Unassigned » igor mashevskyi

igor mashevskyi’s picture

Assigned: igor mashevskyi » Unassigned
Status: Active » Needs review
hockey2112’s picture

I am also receiving this error, and my popup is not appearing. Any fix for this?

hockey2112’s picture

I applied the changes to the two files mentioned in https://git.drupalcode.org/project/simple_popup_blocks/-/merge_requests/..., but the issue still exists.

shivam_tiwari’s picture

Status: Needs review » Needs work
omkar-pd’s picture

StatusFileSize
new19.39 KB

I applied the patch and it worked for me. Attaching a screenshot for reference.

shivam_tiwari’s picture

Status: Needs work » Needs review
hockey2112’s picture

I am using the Bootstrap Barrio theme. I set up the Simple Popup Blocks module according to the documentation, and I downloaded the two modified files from https://git.drupalcode.org/project/simple_popup_blocks/-/merge_requests/... and added them to my install , overwriting the existing files (and cleared cache). Here are the other steps I followed:

  1. I created a region in my page.html.twig called "pop". I added that new region to my theme's .info file.
  2. I created a block called "alertblock" and added it to the "pop" region. It has no page or role restrictions.
  3. I went to /admin/config/media/simple-popup-blocks/add to create the new pop-up. These are the values I used:
    • Unique identifier: alert
    • Choose the identifier: Drupal blocks
    • Blocks list: alertblock
    • Choose Layout: center center
    • Popup frequency: Visit counts: 0
    • Minimized button: checked
    • Close button: checked
    • Show minimized...: unchecked
    • ESC key to close: checked
    • Overlay: checked
    • Trigger method: Automatic
    • Delays: 0
    • Trigger width: blank
    • Width: 400
    • Cookie expiry: 100
  4. I saved the Popup. It is "Inactive". I edited it, and made it Active and saved it again.
  5. I visited the home page of my site, and the pop-up does not appear. I look near the bottom, and I see the popup content in the "pop" region. Therefore, I added the recommended CSS code to my CSS file (#block-alertblock { display: none;}).
  6. I went back to my home page. The popup content in the "pop" region is now hidden, but the popup never appears
  7. Chrome dev console shows many errors like this:
    Uncaught TypeError: $(...).once is not a function (dupal.js?v=10.0.7:64 )
    at Object. (simple_popup_blocks.js?v=10.0.7:113:30)
    at Function.each (jquery.min.js?v=3.6.3:2:3003)
    at Object.attach (simple_popup_blocks.js?v=10.0.7:11:9)
    at drupal.js?v=10.0.7:166:24
    at Array.forEach ()
    at Drupal.attachBehaviors (drupal.js?v=10.0.7:162:34)
    at drupal.init.js?v=10.0.7:32:12
    at HTMLDocument.listener (drupal.init.js?v=10.0.7:20:7)

I have tried it in an incognito window as well, but it doesn't appear there either.

Any idea what I might be doing wrong, or anything else I can check?

Thanks!

hockey2112’s picture

I may have identified the issue, but I still don't know what the issue was.

I uninstalled the Admin Toolbar module and its submodules "Admin Toolbar Extra Tools" and "Admin Toolbar Links Access Filter". The popup began working.

I then reinstalled that module and its submodules one by one, clearing cache each time, and the popup continued to work!

This doesn't make any sense to me. It seems to me that I have now reverted back to my original configuration in which the popup didn't work. Any idea what could have been changed by uninstalling and then reinstalling those modules?

gunjan.a2@tcs.com’s picture

StatusFileSize
new1.47 KB

I have applied the changes provided in https://git.drupalcode.org/issue/simple_popup_blocks-3350919/-/tree/3350... but was still getting js error in console when accessing site as anonymous user. Added patch to resolve the same

gunjan.a2@tcs.com’s picture

I have verified changes provided in https://git.drupalcode.org/issue/simple_popup_blocks-3350919/-/tree/3350...
The issue is not appearing for admin users but is replicable for anonymous users. Attached the patch for the same

gunjan.a2@tcs.com’s picture

agunjan085’s picture

StatusFileSize
new1.47 KB

I have tried the code changes mentioned in https://git.drupalcode.org/issue/simple_popup_blocks-3350919/-/tree/3350...
The issue is not occuring when logged in as admin & the popup is working fine as expected but its throwing error in console when opening site as anonymous user. Attaching patch for the same

agunjan085’s picture

Added core jquery library to the libraries.yml to resolve the console js error for anonymous user. Now the popup is working fine for both anonymous as well as admin user
Issue commit : https://git.drupalcode.org/project/simple_popup_blocks/-/merge_requests/...

nidhi27’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new171.68 KB
new454.38 KB

Verified the MR10 on 10.1.0 and it's working fine.

Earlier it was showing the error in console. After change popup is showing for anonymous users as well.

Added screenshots for reference.

nidhi27’s picture

Issue summary: View changes
nidhi27’s picture

Issue summary: View changes
Yuezhu’s picture

I tried to apply patch with composer on drupal 10, it keeps saying:
Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2023-04-27/uncaught_typeerror_once_0....

agunjan085’s picture

Hi yuezhu Please use the diff from MR https://git.drupalcode.org/project/simple_popup_blocks/-/merge_requests/10 for testing instead of the patch as it was an old patch

Yuezhu’s picture

When will the above merge request be merged?

i-trokhanenko’s picture

Version: 8.x-3.1 » 8.x-3.x-dev

+1 RTBC, please commit

pierreemmanuel’s picture

StatusFileSize
new2.51 KB

Generate patch from MR diff.

hockey2112’s picture

The patch in #25 worked for me.

andrenoronha’s picture

The patch in #25 worked for me.

djween’s picture

I applied patch in #25 and popup works for ADMIN user but not for AUTHENTICATED (non-admin) user or ANONYMOUS user for me.. Sorry, it required me to clear my browser cache for patch to work.

umit’s picture

Patch #25 worked for me. This module now needs to be updated.

vito’s picture

Patch #25 worked for me.

ravi kant’s picture

The MR patch is applying and errors is disappearing.

But the popup is not working with 'Choose the identifier - Drupal Block' but working with 'Choose the identifier - Custom css id or class'.

cestmoi’s picture

I confirm patch #25 works well.

I applied patch #25 on Drupal `10.3.2` / simple_popup_blocks `8.x-3.1` and the issue is gone.
The `Choose the identifier` is `Drupal Block` and the popup is working for admin and anonymous users. The original block is hidden in the theme region and only shows in the popup.

joco_sp’s picture

Priority: Normal » Major

Patch #25 worked for me on 8.x-3.1.
I didn't try the previous solutions, but all once error messages are gone and the popup is working again.

I am changing the priority to Major, because the bug makes the popup unusable.

i-trokhanenko’s picture

Any chance to get a fix committed? Thanks in advance!

mahmoud barhouma’s picture

StatusFileSize
new1.59 KB

patch #25 did not work for me, I suggest that we replace once like patch below

abedmatini’s picture

when i installed this module https://www.drupal.org/project/jquery_once , this error Uncaught TypeError: $(...).once is not a function goes away. but the pop up still not showing up, not sure if i'm missing something else in the popup setup

abedmatini’s picture

I could make it work with CSS Selector id (*).
For some reasons, even if the Drupal blocks is selected, it is still looking for a selector id.

So installing https://www.drupal.org/project/jquery_once as well as selecting Css id (#) and targeting the block by that id, made the pop up visible for me

i-trokhanenko’s picture

Status: Reviewed & tested by the community » Fixed

Committed the patch #25 as it works for most of the users.
@abedmatini, @mahmoud barhouma , please make sure the issue is not related to your custom theme. If not, feel free to open a new issue.

i-trokhanenko’s picture

shivam_tiwari’s picture

Status: Fixed » Closed (fixed)

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