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.

-1
votes
0answers
6 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
24 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
23 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
24 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
0answers
10 views

Content is displaying below the script

In my content, first I'm adding some text, then I'm adding an external JavaScript tag. Example text (in full HTML): I'm working in Drupal7. and then the script tag: <script src="https://XXX" ...
-2
votes
1answer
34 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?
-7
votes
0answers
16 views

How to upload a large files 500-1500 MB and how to restrict the number and time of uploads?

How to upload a large files 500-1500 MB and how to restrict the number and time of uploads? Need to upload genomics FASTQ files. The backend will process them and return results to the email, provided ...
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
16 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 ...
3
votes
1answer
44 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
37 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
29 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
49 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
42 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
34 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
36 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
39 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
37 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 ...
0
votes
1answer
119 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
0answers
7 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
89 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
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
47 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
48 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
66 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
52 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
27 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
53 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
72 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
133 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( ...
1
vote
2answers
115 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
52 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
117 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
52 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
22 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 ...
0
votes
0answers
44 views

How to modify drupalSettings JavaScript in an Event?

I have a UserLogin event subscriber. I want this subscriber to output a variable from marketing tracking purposes to Javascript, however, I don't see how I could accomplish this, as the Event ...
0
votes
1answer
108 views

create new image style using javascript

I am using fancybox JS library for creating a slideshow from a custom bloc with a multivalue image field. it works but the images on the slideshow are small because a style have been applied to the ...
-1
votes
1answer
419 views

jQuery on Twig Template [duplicate]

I am trying to create a basic jQuery function on my twig template but I can't seem to get it to work. Can someone please help me!? My Twig File is as follows: {% block javascripts %} {#if you ...
1
vote
1answer
20 views

Views switches to another view on apply or any change

When I'm working on a block display in Views on Drupal 7, and hit the "Apply" button, I'm taken to the master (or first view), instead of staying on the block display that I'm working on. How do I ...
1
vote
1answer
139 views

What's the correct way to pass variables to the JavaScript of a custom CKEditor plugin?

I saw that we can pass values to our JavaScript using drupalSettings. However, this is for Drupal custom module JavaScript files. Since a CKEditor plugin file is already attached/loaded in a different ...
2
votes
1answer
76 views

What's the difference between drupalSettings and settings parameter in behaviors?

When having the need to pass settings or parameters from PHP to JavaScript, i always used to do so according to a blog post from Acquia - create a dependency to drupalSettings, attach the settings on ...
0
votes
1answer
125 views

How to apply the page-hiding snippet for Google Optimize?

I'm trying to use Google Optimize on a Drupal 8 site through Google Tag Manager. I have set up the tags in Google Tag Manager through Google's UI and used the Google Tag Manager module to add the ...
2
votes
0answers
63 views

Adding an Attribute to a Script Tag Before Src

I'm working with CloudFlare and have identified a script that needs the data-cfasync=“false” attribute applied so CF doesn't touch it. This script is defined in a library in a custom module. my-...
0
votes
2answers
60 views

adding js and css to custom templates

i created a custom module, which renderes a custom template. i followed this tutorial now basically i want to add, bootstrap, jquery, and some custom stling and scripts, I read this article, ...
0
votes
1answer
115 views

Off canvas dialog using a button

I am trying to adapt the relatively new off canvas dialog introduced in Drupal 8.5. It is suggested to use it with the Drupal Form-API and a link element like this: $form['off_canvas'] = [ '#title'...
1
vote
1answer
36 views

Is the AJAX from image fields and multi-line fields breaking my JavaScript?

We have added tooltips to our node form using this method: https://inclusive-components.design/tooltips-toggletips/ It includes a JavaScript/jQuery snippet that works perfectly except... If the ...
0
votes
1answer
99 views

Failed to load popup dialog with in views

I am using Drupal 8.6.1 with the 8.x-1.0-alpha2 Footable module and the core dialog. What I did so far: Install the Footable module. Download the most recent 3.x.x version of the FooTable jQuery ...