Questions tagged [javascript]

Use for questions about JavaScript code that is very specific to Drupal.

Filter by
Sorted by
Tagged with
0 votes
1 answer
23 views

Libraries override jquery_ui_accordion

How can i override jquery_ui_accordion? I can't figure out how. libraries-override: # Does not work? jquery_ui_accordion/accordion: css: component: assets/vendor/...
mgoubert's user avatar
  • 365
0 votes
0 answers
29 views

CSS/JS permissions

When I add CSS/JavaScript to webforms using the menu under settings-> css/js , it works for users with the administrator role, but it fails to work for all other user roles.The page loads but the ...
Aly's user avatar
  • 1
2 votes
0 answers
39 views

Javascript library with "modulepreload"

Lately working with svelte in a project. The generated HTML uses Javascript with link and modulepreload: <!doctype html> <html> <head> ... <link rel="modulepreload&...
Koala Yeung's user avatar
2 votes
0 answers
21 views

jQuery timepicker on custom FAPI form element

How can i add jQuery timepicker to custom form element. There is some description on API docs: #date_time_callbacks: An array of optional callbacks for the time >element. Can be used to add a ...
Ev Tr's user avatar
  • 21
-1 votes
1 answer
65 views

Give all users including anonymous ones the option to add nodes of certain content types to a list like "interested", at least once

I'd like to give all users including anonymous ones the option to add nodes of certain content types to a list like "interested", at least once. The logic is identical to that of a shopping ...
alesios's user avatar
  • 41
1 vote
2 answers
219 views

Why isn't Drupal's core once() function working in my simple test script?

I am trying to console.log a message once and only once in Drupal 10. I am cutting and pasting examples from https://www.drupal.org/node/3158256 into my file and I am still seeing the message appear ...
arnoldbird's user avatar
  • 1,193
2 votes
2 answers
249 views

How to hide CKEditor5 toolbar plugin based on user permissions?

I am using Drupal 10, CKEditor5, and a text format that has a good number of options in the toolbar including the source editing plugin. I have a custom module that defines a custom permission that I ...
Jordan's user avatar
  • 49
1 vote
0 answers
28 views

Widget Field Changed VIA Javascript is empty in AJAX callback

So I am using the Geolocation module, specifically with the google maps API. I have a geolocation field. This field is unlimited to allow for adding multiple points to a map. This all works fine. I ...
Michael Garrido's user avatar
0 votes
0 answers
77 views

What do I need to change in my code that uses ColorBox?

I get the following errors and I am unable to understand why. drupal.js?v=10.1.6:64 Uncaught TypeError: a(...).colorbox is not a function at HTMLDivElement.<anonymous> (nacolorbox.js:19:11) ...
Delford Chaffin's user avatar
0 votes
1 answer
55 views

Respond to "dialog:afterclose" once

I'm trying to figure out how to respond to dialog:afterclose only once, and I'm not having any luck getting the syntax right (and I'm having trouble finding resources because most search results refer ...
Noah's user avatar
  • 1
1 vote
3 answers
1k views

Why does this JavaScript once implementation not work? [closed]

attach: function(context, settings) { console.log('enter'); var element = once('addedtocart', '#addtocart', context); element.on('click', function () { var ...
Z CHAMP's user avatar
  • 62
0 votes
1 answer
58 views

A Drupal.behaviors stops working when I update the module

I have checked the field_ui core module to understand how to update my code, but it doesn't seems to work. This is the code. (function ($, Drupal, drupalSettings) { Drupal.behaviors....
Oskar Calvo's user avatar
-1 votes
1 answer
105 views

jQuery selector does not find the view content after document.ready event

I am applying some jQuery to make a slick carousel from a Drupal view. The carrousel does not work erratically on page load; sometimes, it does, sometime it doesn't. jQuery(($) => { $(document)....
Matoeil's user avatar
  • 3,429
0 votes
0 answers
83 views

Form States not working when compressed javascript is enabled

I have visible states setup for a 2 fields that correctly work when javascript aggregation is disabled. When I turn JS aggregation on both fields are visible no matter what option I select on the ...
blu's user avatar
  • 438
0 votes
0 answers
190 views

How can I disable a specific javascript function in my base theme?

There is a single javascript function in my base theme that I want to disable and I haven't been able to figure out how to do that. I have read the documentation on how to disable a whole file with ...
Eluchel's user avatar
  • 387
0 votes
1 answer
109 views

How can I add an external/third party library with type = 'module' using drupal_add_js()?

drupal_add_js('path_to_external_JS_file_on_CDN', [ 'every_page' => TRUE, 'type' => 'external', 'defer' => 'defer', 'attributes' => [ 'async' => true, 'type' =...
monster_energy's user avatar
0 votes
1 answer
286 views

How can I add drupalSettings values with the #attached array?

In D7, we have used drupal_add_js with DrupalSettings for accessing php variables to javascript files, for that we have used in D7 in my custom function like below function custom_function($data) { ...
somasundaram's user avatar
0 votes
0 answers
47 views

Why is my javascript settings variable empty in Chrome/Edge, but it works in Firefox?

My javascript file starts like this... var my_global_var; (function ($, Drupal, drupalSettings) { 'use strict'; Drupal.behaviors.myBehavior= { 'attach': function attach(context, settings) { ...
arnoldbird's user avatar
  • 1,193
0 votes
0 answers
111 views

Select media popup is not opening after upgrade ckeditor from 4 to 5 Drupal

We have drupal version 9.5.7 in our website, When we had upgrade ckeditor4 to ckeditor5 then Select media popup(for image and video) is not opening. Console error: ajax.js?v=9.5.7:411 An error ...
Jasbir's user avatar
  • 101
0 votes
0 answers
152 views

How can I fire a Google analytics tag event on every form post?

I want to see statistics for forms submissions, grouped by type of forms. I am using Google Analytics 4 (https://www.drupal.org/docs/contributed-modules/google-analytics/using-google-analytics-4x). I ...
user5274714's user avatar
0 votes
0 answers
37 views

Use javascript code in a specific div of the webform page

I have a website that was set up using Webforms with page breaks. So on the same URL, there are multiple "pages" and div blocks on each page, with a progress bar on top so you know what &...
Rachel C's user avatar
1 vote
0 answers
127 views

How do I alias jQuery to $ before loading a remote library?

I am trying to use Bootstrap autocomplete in my module. I added this to my .libraries.yml. bootstrap-autocomplete: remote: https://bootstrap-autocomplete.readthedocs.io/en/latest/ version: 2.3.7 ...
Francesco Marchetti-Stasi's user avatar
0 votes
1 answer
192 views

Use AJAX On Node Add Form To Change Field Required Status

On a node/add form I have a pair of fields that need to be able to control one another. The first field allows a user to enter a birthdate, the second field allows the user to say the birthdate is ...
Drupal Learner's user avatar
1 vote
0 answers
88 views

How to subscribe to a view render event?

I'm writing a module that will inject javascript into the page when a view is rendered. The contents of the javascript will depend on the results returned in the view, so ideally I would have access ...
Andrew Clemens's user avatar
0 votes
0 answers
78 views

Views UI javascript is broken

I discovered today that the Views UI is broken on one my sites. I'm not sure when it broke, because the Views UI is not one of the things I check after updates. I'm currently at 9.5.3. My Views UI ...
Menno van den Heuvel's user avatar
0 votes
1 answer
340 views

Dynamicaly add ajax form item and add event on checkbox

I've added an ajax callback to my form to add some data on it : $form['add'] = [ '#type' => 'button', '#value' => t('add'), '#ajax' => [ 'callback' => [$this, '...
lobafox's user avatar
  • 113
0 votes
1 answer
248 views

Add js library to custom ckeditor4 plugin

How can an external JS library be integrated into Drupal for use within a custom Ckeditor4 plugin? My custom plugin needs to set a javascript cookie each time I click on the plugin icon and unset when ...
sisko's user avatar
  • 1,720
1 vote
1 answer
115 views

How to translate a link defined in javascript with Drupal.t()

I have a template string that contains a link, which I want to translate afterwards throught the Drupal UI: var html = `<p>${Drupal.t('<a href="/node/16">Check this out</a>'...
donbuche's user avatar
0 votes
1 answer
59 views

How do I lock down a child theme to use jQuery 3.6.0?

My older site uses bootstrap 3 and has been working great when accessed from a mobile phone and the hamburger menu kicks in, but something has happened in jQuery 3.6.2 (In Drupal 9.5.0) that causes ...
Mr.C's user avatar
  • 1
0 votes
0 answers
87 views

Ajax call brings all the Javascripts of drupal ruining the original page javascript

Based on this solution https://www.drupal.org/docs/7/api/javascript-api/simple-drupal-ajax-load-with-jquery-and-delivery-callback I'm brining with an ajax call, a multistep form. The ajax brought ...
MMT's user avatar
  • 41
1 vote
1 answer
102 views

Can we export json schemas for type script usage?

We have a Drupal installation that acts as a backend and a front end that uses the HttpClientModule from Angular to query this data. Thanks to the typescript base, we can provide the functions of this ...
flauschi's user avatar
0 votes
1 answer
270 views

Why don't I see Asset Injector code directly in the HTML?

I’m having trouble getting the Asset_Injector module to work, and would like to find out why it's not working.   As a simple test, I want to insert some CSS using the module’s CSS injector: #container ...
bburch2000's user avatar
0 votes
3 answers
2k views

Google API callback doesn't work

I've created this javascript (delivery.js) that is supposed to take a pre-existing div on a webform page and append a Google Map to it, along with a few circles of differing radius. Here is my ...
Riley Lutz's user avatar
0 votes
2 answers
215 views

Webform javascript CSS selectors with table

I'm currently trying to add javascript via the settings tab for a webform that is supposed to dynamically update the displayed totals at the bottom of the webform page for the user. A part of this ...
Riley Lutz's user avatar
-2 votes
1 answer
347 views

How to load a dependency in the <head> in drupal 9?

I have followed the official documentation, but it doesn't work global-styling: version: VERSION js: js/bootstrap.min.js: {} js/custom.js: {} css: component: css/style.css:...
user31782's user avatar
0 votes
1 answer
104 views

I can't load inline jQuery

I have a Drupal 9 page, where I am trying to load some inline jQuery code, from CKEditor, but it isn't working and I am not getting any error on the console. This worked perfectly in Drupal 8. <...
KVF-IT's user avatar
  • 31
0 votes
0 answers
105 views

Why does adding data- attributes to JavaScript libraries prevent them from being aggregated?

I'm having an issue with adding a data attribute to my preprocessed / aggregated javascript within my theme. When I have preprocessing disabled, I am able to add a data attribute to individual files ...
Ian's user avatar
  • 1
1 vote
1 answer
124 views

drupalTranslations is not defined [closed]

I'm an Angular front-end developer. I work with a team that uses Drupal for content. The scenario is that we use Drupal.t() to translate the strings. When I translate the word from the back-office, it ...
TheScripterX's user avatar
0 votes
0 answers
85 views

Submit webform via custom button

I want to update a webform submission via custom button. On the same page as my webform I created a custom button in a block. <button id="myButton" onClick="submitWebform()" ...
Monster97139's user avatar
0 votes
0 answers
211 views

How can I add inline JavaScript on a page returned from a custom controller (not with a library)?

How can I add another render element that contains my custom JavaScript code? Do I use ['#attached']['html_head'] or code similar to the following one? $build['body']['script'] = [ '#type' => '...
mevsme's user avatar
  • 1
3 votes
1 answer
356 views

Is there a way to define a JS library that will use a CDN as a fallback

Is there a way to define a JS library that will use the CDN as a fallback? Example: Define a billboard.js library that will use the local version of files from libraries directory and fall back to one ...
Pjotr's user avatar
  • 165
-1 votes
1 answer
857 views

How do I implement an AJAX callback?

Given is a Drupal 9 project. How can I make use of Drupal functionality through an AJAX call? web/modules/custom/mymodule/src/Appointment.php namespace Drupal\mymodule; class Appointment { public ...
Kevin Matsubara's user avatar
-1 votes
1 answer
333 views

'setAttribute' causing UncaughtDOMException with jQuery Dialog?

I'm using jQuery and the jQuery UI Dialog module (here) to check for new nodes of type "call" every few seconds. Forgive me if I don't know too much about it as I just started using it. Here'...
Riley Lutz's user avatar
0 votes
1 answer
159 views

Not receiving dropdown of custom autocomplete textfield

I am currently trying to create a postcode lookup which returns a street name in an autocomplete dropdown. To do this I have created a new module containing the following files: src/Controller/...
JCMSmith's user avatar
1 vote
0 answers
305 views

JSON-API upload image file

I have been struggling to set up headless Drupal with React js. I did manage to upload the image via JSON API, as per instruction here But I am not able to display the image. It would be great if ...
Rdb's user avatar
  • 11
0 votes
0 answers
194 views

Custom block JavaScript not loading for anonymous users

I've created a custom block (via Drupal admin) that uses Twitter's API to insert tweets into a page. The necessary JavaScript loads for authenticated users but not anonymous users. I configured the JS ...
Brian Zelip's user avatar
0 votes
1 answer
209 views

Toggle (show or hide) visibility of content type field in view depending on relationship with other content type

I have a member content type that displays info about a company's member. One of the fields is named member publications, and it's a link to a blog view where the publications of the member (another ...
Gabri's user avatar
  • 3
0 votes
0 answers
100 views

Manipulate the DOM with jQuery just before the page loads

Because of accesibility tests i need to manipulate the html of my page just before it loads completely. I dont want to manipulate contrib modules i am using, so i need to do it with jQuery. In fact, i ...
leandro713's user avatar
1 vote
2 answers
71 views

Make views output more dynamic with knockout.js or other similar framework?

I am currently experimenting with knockout.js so i can make views output more dynamic. I know React and angular among other newer frameworks are recommended but i do not want to create single page ...
Shawn Becker's user avatar
1 vote
1 answer
3k views

Is there a way to use jQuery?

I heard Drupal 10 will no longer support jQuery out-of-the-box. Is there a way to use jQuery in Drupal 10? My guess would be that adding jQuery to a module's composer.json file would allow jQuery code ...
pmagunia's user avatar
  • 697

1
2 3 4 5
65