Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [javascript]

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

0
votes
0answers
14 views

How to add 3d party js library to the project?

For my D8 project I am doing some optimization for mobile devices, and for node views it is very important for us to implement hyphenation for the titles. Based on my research the css property hyphens:...
-1
votes
1answer
35 views

JS function undefined although JS framework attached

I attached materialize to my library theme. global-styling: version: VERSION css: base: materialize/css/materialize.min.css: {} css/style.css: {} js: materialize/js/...
1
vote
1answer
25 views

Why is the jquery_update module not supporting the latest jQuery version?

The recommended jquery_update module only supports 1.10. Why recent jQuery security version 3.4.1 not updated? https://jquery.com/download/ So is it recommended to make my Drupal site to update with ...
-1
votes
1answer
18 views

Drupal theme error. functions from add on libraries are not included when running my custom script [duplicate]

I'm trying to load a javascript function in my custom script with jquery and materialize. When the script load it says Uncaught TypeError: $ is not a function and sidenav() is not defined. My ...
1
vote
0answers
26 views

Adding pre built create-react-app to D8 block [closed]

this is my first question here!, so strap on in as this will be good! I want to know how to add a pre "built" react app to a block, created with `npx create-react-app reasons are i want to use a ...
0
votes
1answer
38 views

How to make get for drupal behaviors to run only once?

Drupal.behaviors.js_mod = { attach: function (context, settings) { //$('body', context).append(chart); // $( '#drupal-myradar', context ).once $.get( "/web/js/mod", function( data ) { ...
0
votes
0answers
76 views

Adding jQuery to a webform

Trying to count selected radios in a webform, I managed to make it work outside drupal (please see link below) but I'm not sure how to add it to my theme/webform. https://jsfiddle.net/j9q75Lay/ I ...
0
votes
0answers
20 views

How to move js in header from footer in D8 [duplicate]

I am using twitter bootstrap theme in drupal 8. By default bootstrap.js and jquery.js loaded in footer. I want to override the order of these js and place in header. Please let me know if its ...
-1
votes
1answer
57 views

Custom code doesn't work [closed]

i tried to add some code to my theme, following this: How do I include JavaScript on a single page in a way that is amenable to scale i created my js file in: C:\xampp\htdocs\drupal-8.7.2\themes\...
-1
votes
0answers
15 views

Confirmation popup Box according to a condition on submit button

I am using Drupal 7. In my list I have 2000 subscribers. Now I want a confirmation box before executing the form. The only issue is If I have more than 20 users I want the confirmation form to ask ...
0
votes
0answers
32 views

Ajax implementation in exposed forms

We use to add property '#ajax' to a form element in our form array, to trigger an Ajax response and it works fine except in case of views exposed forms. This doesn't work in case of views exposed ...
1
vote
2answers
106 views

Custom module javascript Drupal.behaviours doesn't seems to load

I have a custom module which has a javascript file. Here's the content of the javascript file: (function ($, Drupal) { Drupal.behaviors.promotionalOverlayBlock = { attach: function(...
-2
votes
1answer
32 views

Custom search function with result from external url

I need to create a page in Drupal 8 where there is a text field and a search button. When the user has entered a word to search and hit the search button a list with a search result should be ...
0
votes
1answer
26 views

How to use date_date_callbacks

In Datetime.php from Core\Datetime\Element, I read: #date_date_callbacks: Array of optional callbacks for the date element. Can be used to add a jQuery datepicker. What does it mean? How am I ...
1
vote
0answers
28 views

Why do I get “Warning: Division by zero in __TwigTemplate”? [closed]

I created the connectedFilters.js file in /themes/custom/module/js/ with the following code. (function ($, Drupal) { Drupal.behaviors.connectedFiltersBehavior = { attach: function (...
1
vote
1answer
35 views

Manually trigger AJAX from custom JavaScript

I'm in the process of developing a form where the user enters a UK postcode and the textfield is replaced by a select list. This all works quite nicely when using the blur event, but it is not always ...
-2
votes
1answer
47 views

Update jQuery version on drupal 7.59

I'm newbie in drupal. Currently, my site is running on drupal 7.59 and jQuery 1.5. Is it possible to update jQuery version to 3.4.0?
0
votes
0answers
24 views

Using Raphaël JavaScript library

I'm trying to use Raphaël with a Drupal 8 website. I'm wondering if there's a step I'm missing, or maybe some other issue, as it doesn't seem to work. I suspect I'm just missing a step in using extra ...
0
votes
1answer
17 views

How do I create a log/statistics of on page events?

I am using drupal 7, I have seen there are already statistic modules but can't find any for my situation On my website I am trying to track certain on page activities which site admins can see in a ...
2
votes
1answer
46 views

how to prevent javascript from running again when an AJAX form is submitted

I have this code in a javascript file to hide some search filters... $('#views-exposed-form-faceted-search-page .form-type-select').once().hide(); The user can toggle the visibility of the filters ...
1
vote
1answer
55 views

How to load jQuery UI after bootstrap js files?

I'm a newbie to drupal 7, And I'm facing a conflict between jquery.ui.button.js and bootstrap/button.js because jquery ui is loaded before bootstrap. How can I change the order and load jquery ui last?...
0
votes
0answers
32 views

How do I add custom JavaScript code after execution of google chart loader?

In hook_preprocess_page(), I added a custom JavaScript file used for adding a chart to the page. drupal_add_js(drupal_get_path('theme', '****') .'/js/loader.js', array('type' => 'file', 'scope'...
0
votes
0answers
40 views

Add script to a view [duplicate]

I've downloaded this to my theme folder and added scripts[] = easytree/jquery.easytree.min.js to my theme.info, how do I call it to be invoked on a particular views path? I would like to use the path ...
0
votes
0answers
24 views

How can I access/inject external objects into my custom code at runtime

I have seen similar questions to this but none appear to directly and generally answer this question. I want to add some custom.js to a module using libraries.yml file and in custom.js I want to ...
0
votes
0answers
51 views

Geofield Map - Show marker popup by clicking the filtered Title

I'm facing a problem with geofield map and I can't find a solution. So I have a view with all nodes of a content type, where I add an attachment of geofield map format. There I show all nodes from one ...
2
votes
1answer
48 views

How to properly attach Google Maps Api to Drupal behaviors in Drupal 7?

So, I've posted on this elsewhere and I seem to either get half answers but they've gotten me closer to a solution but not over the finish line. I'm trying to implement a custom Google Maps ...
0
votes
1answer
36 views

How do I include an affiliate script?

I am trying to add an affiliate script to my Drupal 7 website. I am doing this in a custom block. Specifically, I create a block, select the scripts text format in my WYSIWYG Editor, add the script ...
0
votes
0answers
43 views

drupal_add_js is adding .js file to footer despite me adding 'scope' => 'header'

I want to add an external file to the header. To that affect I copied what others have done and used drupal_add_js();: drupal_add_js('somefile.js', [ 'type' => 'external', 'scope' => '...
0
votes
0answers
43 views

Javascript not working for unauthenticated users

I have some script for a "back to top" button. The script works fine when I'm logged in, but it does not work when I'm logged out. I've read about dependencies, but I think I'm doing them correctly: ...
0
votes
1answer
43 views

How to reference external JS callback in custom module

So I apologize if I mess the terms here up, I'm relatively new to using jQuery in Drupal. I'm trying to implement a custom Google Map application with the V3 API. When I started mocking the module up ...
1
vote
1answer
146 views

Infinite scroll is firing multiple times

I have looked for other answers on the same topic but still cannot find a solution why the event is firing more times in my code: (function($, Drupal, drupalSettings) { Drupal.behaviors.news = {...
0
votes
1answer
27 views

Adding core Javascript libraries in my_module.libraries.yml

I've read Adding stylesheets (CSS) and JavaScript (JS) to a Drupal 8 module and I can see where you can add assets that are part of your module or from a CDN or external source. What about if that ...
0
votes
0answers
9 views

How to consume Views GeoJSON in a custom JS map application?

I'm trying to implement a custom Google Maps implementation that uses data from Views GeoJSON feeds. I need a custom approach as I need to be able to add multiple data layers. So, I need to grab the ...
1
vote
2answers
130 views

Control Webform's date field (datepicker) from JS

I have to change number of months that's shown in datepicker of my date field in Webform, on desktop I need 2 months, but on mobile just 1. I'm not able to control that using JS, so I created patch ...
0
votes
0answers
18 views

How does drupal recognize the external js library imageflow with the libraries module?

I want to upgrade the imageflow module to drupal 8. Therefore I created a module "myimageflow". "myimageflow.libraries.yml" seems to be ok according to function myimageflow_library_status(), but ...
0
votes
0answers
26 views

Implementing document.ready() [duplicate]

I have some javascript code (as listed below) that I once used on a different non-drupal site. I would like to implement the same code on my custom theme. my research says i need to use drupal....
1
vote
1answer
50 views

How to add google maps js without breaking jquery?

So, I'm trying to implement a custom map using the Google Maps API in addition to a Google Map view. I'm working with an up-to-date D7 install. The reason for this is that I need to have multiple ...
0
votes
2answers
51 views

Exclude a JavaScript file from a node

I'd like to exclude a js file from loading on to a specific node. Right now my libraries.yml file looks like this: global-styling: version: 1.x css: theme: css/bootstrap/bootstrap.css: ...
-5
votes
1answer
97 views

How to refresh a view automatically?

I have a Drupal 8 site with NodeJS. I use the following module: https://www.drupal.org/project/private_message_nodejs For the installation, I followed the instructions in the documentation of the ...
1
vote
1answer
53 views

Drupal.behaviors, attach and origin of it

The structure of Drupal.behaviors is rather similar in Drupal 7 and Drupal 8. Where do attach() and detach() come from? Thid code is from drupal.js , still wondering where attach method in this.attach ...
0
votes
0answers
34 views

Use colorbox node from a jquery command on a basic page?

I'm trying to open up a node via the Drupal 7 Colorbox Node module on a basic page using jQuery and hooks from a map. I can get colorbox to put up a HTML pop-up using this code: <script type="...
0
votes
1answer
54 views

How do I implement a one page navigation with anchors?

So the specific functionality I'm looking for is a link on one page (e.g. drupalsite/home) leading directly to a specific section of another page (e.g. a section on drupalsite/otherpage). I believe ...
0
votes
1answer
21 views

Change input value on click when there is more than one paragraph

There are two fields on my paragraph. A number field A text field I want to change the value of the text field when I click on the number field. Here's my script so far which is only good on ...
0
votes
1answer
86 views

AJAX SettingsCommand Usage

Class Documentation: SettingsCommand I'm trying to figure out how to use this Ajax Command correctly. I must be confused from the documentation, so I'm hoping someone can shed some light where I'm ...
0
votes
1answer
162 views

How do I enable an onclick event in a link on a form?

I am using the following code. $form['test'] = array( '#type' => 'link', '#href' => "javascript:;", '#title' => t('Show'), '#attributes' => array( ...
2
votes
2answers
128 views

Equivalent method or “body onload”

First, I have tried for several hours to weed through the various search results of the keywords above. I've found several things that seem to answer this but they're for D7, one of them from 2012 ...
0
votes
2answers
57 views

How to add javascript with #attached in a node which contains a specific paragraph bundle

I need to attach js in all nodes with a specif paragraph bundle. I know how to do this with drupal_add_js, but i prefer don't use it to prevent cache problems. I am trying with hook preprocess_entity ...
0
votes
1answer
146 views

Slide effect with JQuery [closed]

I'm not very good with Javascript/Jquery, and I don't understand something. I display a full size image when the user arrives for the first time on the homepage. If the user scrolls, the image ...
0
votes
1answer
55 views

Using JCF with dynamic forms

I want to use Javascript Custom Forms (JCF) to get more attractive and consistent looking forms on my Drupal 7 site. I've got it working to a degree, however when the form changes with AJAX, the new ...
2
votes
1answer
24 views

Override one line in core tabelselect jQuery behavior so custom checkboxes aren't affected

I have created a custom table using a Form API tableselect element, and within my table, I have embedded a checkbox form element that is checked based on an entity field (see here for details). The ...