Skip to main content

Questions tagged [javascript]

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

Filter by
Sorted by
Tagged with
1 vote
1 answer
1k views

Attaching Theme Library to Custom Module

I have a subtheme called bootstrap_subtheme. It has a library called global-styling. I created a custom module called telephone_alter. In telephone_alter.module, I have the following: function ...
Armando Silva's user avatar
0 votes
1 answer
90 views

why my custom jquery code stopped working on a multipage webform after upgrade to WF x6

I have a long questionnaire as multi-page webform and I do many mostly simple counting and addclass using jquery done via a custom module I made for the purpose. This was perfectly working before on ...
Adam888's user avatar
  • 97
0 votes
1 answer
209 views

How to access backbone model from custom javascript outside of view

I was wondering if there is a way to access backbone model variable outside the scope of the backbone model/view.This is the backbone model: function (Backbone, Drupal) { Drupal.addToCart....
briast's user avatar
  • 654
0 votes
1 answer
36 views

How to add JavaScript to a specific View if I don't know the node?

I've seen the answer here using the NID but I don't know this, I only have the URL. Is there is another way to do this please? function MY_THEME_preprocess_node(&$vars) { if($vars['nid'] == '...
stevensunsunsun's user avatar
1 vote
1 answer
282 views

When passing a variable from a render array to JavaScript how do you reach that variable in your Javascript

I add a variable in the backend to a render array like so (removed superfluous code): $some_var = 'Hello World'; return [ '#attached' => [ 'drupalSettings' => ['someVar' => $some_var], ...
AndrewRMillar's user avatar
2 votes
2 answers
2k views

How do I pass a value from PHP to JavaScript from a function that returns a render array?

I'm trying to send a variable to my JavaScript. I would like to send a class name to my twig template and the same class-name to my javascript from a function that returns a render array. The function ...
AndrewRMillar's user avatar
0 votes
0 answers
473 views

Bigpipe after load event

When I enable the bigpipe module most of the blocks disappear, since I use a Vue layer. I've tried the following codes but none of them have worked for me: var charging_blocs = $('[data-big-pipe-...
Javier Rey's user avatar
0 votes
1 answer
1k views

Do we have an option to change/override the drupalsettings variable which is defined by some other module through our custom module?

What is the best approach to change/override the drupalsettings variable which is defined by some other module (basically core) through our custom module ? If I follow the same hooks then how to call ...
Juyal Jee's user avatar
  • 213
2 votes
1 answer
825 views

Javascript file is being included but console.log wont work

So I THINK I have configured my javascript right in that i want to inlude two files. leaflet.js and mappingsource.js and currently on the page source there exists this: <script type="...
Sean's user avatar
  • 23
0 votes
2 answers
914 views

Trigger a behavior from another module in Javascript?

The block_ajax module defines a behavior in its module: https://git.drupalcode.org/project/block_ajax/-/blob/8.x-1.x/js/refresh_ajax_block_command.js I want to initiate this call every 60 seconds so ...
Kevin's user avatar
  • 27.9k
1 vote
0 answers
463 views

How to include external libraries placed outside the webroot in a custom module?

I'd like to use an external library in my custom module. So, I added it as a dependency in the composer.json of my custom module. Since the drupal/recommended-project template places the vendor/ ...
Kwadz's user avatar
  • 489
0 votes
0 answers
42 views

Not able to load data from cookies until I clear cache [duplicate]

In my Drupal application, I have set some cookies through a javascript onClick method. However, am not able to access the data until I clear the cache(admin/config/development/performance/clear ...
Mann's user avatar
  • 101
1 vote
1 answer
2k views

How to preload a css/js library programmatically after module installation? is there api for changing *.library.yml file?

i would like to develop a module where i cached internally html,css,js statically for pages. 1) in a admin setting page i can add a bundle with 1 html page + css/js files. 2) for each bundle i have ...
cristian lorenzetto's user avatar
2 votes
1 answer
86 views

Does requiring core/drupal load jQuery in custom script files?

I am trying to understand a bit more about where and how jQuery is loaded in Drupal 8. If I write a custom script file that will include some translation strings using Drupal.t(), I need to add core/...
Prestosaurus's user avatar
  • 2,067
0 votes
1 answer
223 views

Modifying CKEditor toolbar at runtime

We have a requirement that our standard CKEditor toolbar omit a specific button on only one content type. It seems silly to create a brand new text format just for this. I'm able to modify the toolbar ...
user83736's user avatar
1 vote
0 answers
233 views

How can I pass updated views result to drupalSettings?

I've created a custom views style plugin. I'm trying to pass the views results into a drupalSettings. I'm able to access the dataset like below using the template_preprocess: $variables['#attached'][...
Maddie's user avatar
  • 334
0 votes
1 answer
34 views

Adding JS script, how to format JS

I am trying to add this simple script to my block <script> const config = { sourceAssetAddress: null, sourceAmountDecimal: null, destinationAssetAddress: null, ...
Blissful's user avatar
  • 691
0 votes
2 answers
2k views

Javascript loaded via DrupalSettings variable not executing?

I have added a js library and associated code to get all Location nodes onto a Map page This code works fine if I paste it into the map.js file but if I use the drupalSettings variable, the code is ...
dave t's user avatar
  • 13
0 votes
1 answer
517 views

jQuery once callback function is not called [duplicate]

I'm struggling with the once function. The once callback function is not called. I'm trying to use like this: (function ($, Drupal){ Drupal.behaviors.my_module = { attach: function (context, ...
golddragon007's user avatar
2 votes
1 answer
3k views

How should I replace jQuery UI dialog?

I try to use jQuery UI dialog. Based on this, I put this in a node: <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/...
gbmapo's user avatar
  • 1,086
0 votes
1 answer
469 views

Adding Vue.js to my theme with Webpack not working

I am trying adding Vue.js into my Drupal 8 theme with my Webpack setup (which I had already working). It's all compiling fine with Webpack, without errors after my npm script npm run build. In my ...
meez's user avatar
  • 1,333
0 votes
1 answer
19 views

Hiding view filter option based on another filter selection

I have a view with search criteria and the search criteria looks like below: Age group(options: new born, toddler, pre-school) Classroom (options: NA, potty-trained, transition, not-trained) All ...
Rick's user avatar
  • 125
0 votes
1 answer
115 views

Drupal 8 Accessing Menu Tree in a Block's JS

How can I pass the menu into a block's javascript? I am trying to build a block for a custom mobile menu (client wants specific logic/animations/etc) and use that in Structure > Block layout > Main ...
av0000's user avatar
  • 111
3 votes
1 answer
527 views

Understanding behaviors

I created a custom theme (a sub-theme of Radix base theme). I am loading a custom Javascript file (radix_sub.script.js) using the module libraries.yaml file like below: style: version: VERSION ...
MrUpsidown's user avatar
0 votes
1 answer
369 views

How can I change the 'type' of Drupal script tags from text/javascript to text/plain?

I could use some assistance in figuring out a way to change script tags for a Drupal 7 site to be "text/plain" instead of "text/javascript" And additional attribute(s). I can tell already that ...
Michael Bopp's user avatar
0 votes
1 answer
122 views

In node add, how to upload file using image from clipboard

How can I paste image from clipboard and save into image_field ?
DanielRatk's user avatar
6 votes
1 answer
4k views

Why does this simple javascript execute multiple times?

Why does this javascript execute 2-4 times per page load: // mei_library_turn.js (function ($, Drupal) { Drupal.behaviors.mei_library_turn = { attach: function() { console.log('ready1'); ...
arnoldbird's user avatar
  • 1,237
2 votes
1 answer
1k views

Why is libraries-override not removing assets?

My attempt to remove CSS and JS assets is not working. I have placed the following declarations in my module's *.info.yml file. But after clearing the cache, I still see the assets in the head of ...
arnoldbird's user avatar
  • 1,237
1 vote
0 answers
349 views

JavaScript not executed before PDF gets generated

Using Entity Print 8x-2.1, I've got everything working great (thanks to the developoers of that module) except it does not appear to support loading the javascript portion of attached libraries. CSS ...
Liz Ward's user avatar
1 vote
1 answer
716 views

How to call custom javascript function defined in js file from .module file

I have some custom menu defined for which in the page callback function I want to execute some javascript function defined in some js file which is included in .info file. The alert and console.log ...
roger123's user avatar
0 votes
1 answer
130 views

How to set Ajax callback from jquery on node edit form?

I must to create a dependent Fields with three fields in my content type. This fields are select list, but the options for each Field will be prepopulate from a sql query on external DB. So, this is ...
Prof's user avatar
  • 69
0 votes
0 answers
25 views

Get data from one editor field and pass that into another editor field

I have no idea if this is even possible, but I figured I'd ask anyway. I'm working with a site that is on Drupal 8, and long story short, we don't have access to extending nor updating much so any ...
ultraloveninja's user avatar
4 votes
1 answer
743 views

Is it possible to pass variables as arguments to *.libraries.yml?

Say I have a foo.libraries.yml defined as so: external.bc.js: version: 1.x js: //players.brightcove.net/{{variable here}}/{{variable here}}/index.min.js: { type: external, minified: true} ...
plambre's user avatar
  • 215
0 votes
1 answer
554 views

How to load a internal page content within div? [closed]

I have following code in a basic page on drupal 7 <h2 id="tabs">Test Title</h2> <!-- Nav tabs --> <ul class="nav nav-tabs"> <li class="active"><a href="content/test" ...
Tapash's user avatar
  • 157
0 votes
1 answer
914 views

How to log to console when in a Drupal attach behavior?

I'm using Drupal 7. I have the following code that tries to log to the console: function mymodule_get_jquery() { $jquery = <<<JAVASCRIPT console.log("here"); (function($) { ...
MrSnrub's user avatar
  • 285
7 votes
1 answer
347 views

Understanding State of JS in Drupal

I have a simple contributed module that I have written. It has pretty basic javascript. I decided to clean it up and write it in vanilla js, removing jQuery since that seems to be the direction we're ...
xpersonas's user avatar
  • 542
0 votes
0 answers
581 views

Variables in drupalSettings get cached

I am using the value of a field in the page as a variable. I am trying to use it in the page somewhere else but I think that there is a problem with the cache because the value is sometimes available ...
rebecca mantel's user avatar
6 votes
3 answers
3k views

Using #states in a form with checkboxes

I would like when a client check one of the checkboxes, a text field appeares. Example: if he clicks on 3 checkboxes, all the textfields of the 3 show off. My #checkboxes : $form['input']['...
StefanYYC's user avatar
0 votes
0 answers
199 views

How can you pass the value of a variable from drupalSettings to an iframe in the same page?

I have a variable in Drupal settings which gets its value from php. (function ($, Drupal, drupalSettings) { /** * @namespace */ Drupal.behaviors.pdf_appAccessData = { attach: function (...
rebecca mantel's user avatar
1 vote
1 answer
534 views

Node content is not shown

I installed DrupalGap. Everything works fine so far, except that the node body is not displayed. I have none of the mentioned interfering modules installed. I also tried with a fresh Drupal 7 ...
xandi's user avatar
  • 13
0 votes
1 answer
300 views

js file in custom module's library is not attached when big pipe is running

I have a custom module, filter_component, that provides a form. In the form I have: $form['#attached']['library'][] = 'filter_component/filter-component'; In filter_component.libraries.yml I have: ...
JAyenGreen's user avatar
2 votes
1 answer
3k views

drupalSettings value is undefined [duplicate]

I am trying to call a JavaScript function when I click on a button in a form. I have multiple buttons in a for loop and I have attached the library to all those buttons. (Not sure whether this is a ...
ktrev's user avatar
  • 139
1 vote
1 answer
2k views

How do I add inline JavaScript to the footer? [duplicate]

I want to add third-party JavaScript code at bottom of the every page. I build an module and I am able to add the JavaScript on the head tag, instead of footer. I am using the following code. ...
user3463733's user avatar
1 vote
1 answer
67 views

Override contrib Disqus behavior settings

I want to override a contrib module's library setting that is being attached to page using hook_js_settings_alter(). But, I am unable to change the setting that is being called in js. Here is the ...
Kiran's user avatar
  • 261
2 votes
1 answer
2k views

How do I render a submit button so that it's disabled initially and enabled by JavaScript?

We have a form that includes a React JS frontend component. The component collects some required information, which the React component then supplies to the backend by populating a hidden form field. ...
GuyPaddock's user avatar
1 vote
1 answer
801 views

How to create a select drop down that opens a URL?

I have a select drop down. When the user selects a value from the drop down, the user will then click on a button and based on what the user has selected it will open a url in a new tab. While this is ...
lolname101's user avatar
0 votes
2 answers
464 views

Override a CSS or JS file from the parent theme

Adding in the child theme a CSS file with the same name as the parent theme CSS file overrides the parent file. It doesn't seem to work JavaScript files. How can I override a JavaScript file loaded ...
Matoeil's user avatar
  • 3,443
0 votes
0 answers
346 views

How to Resolve CORB Issue using Drupal Docker Container

I'm running the latest version of the Drupal docker container. I'm trying to make a GET API call via Javascript and I'm receiving back CORB (cross-origin-read-blocking) errors in the Console when ...
jeffnaismith_design's user avatar
-2 votes
1 answer
44 views

Fetch live data (json) and make accessible to javascript or javascript library (React)

I've built a service that returns data from an external API (in JSON format). I do not want to render that directly onto a page or store it in a node but rather make it accessible to javascript/...
sea26.2's user avatar
  • 1,024
1 vote
1 answer
142 views

How to prevent drupalSettings to sort settings object

I attach drupalSettings in a preprocess hook using code similar to the following one. $settings = [ 'bcd' => 'BCD', 'abc' => 'ABC' ]; $variables['#attached']['drupalSettings']['options'] =...
berramou's user avatar
  • 7,245

1 2 3
4
5
65