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 custom js after execution of google chart loader js in drupal 7?

Under hook_preprocess_page function, added custom js file used for adding a chart on the page. drupal_add_js(drupal_get_path('theme', '****') .'/js/loader.js', array('type' => 'file', 'scope' =...
0
votes
0answers
29 views

Pager twig can't access to my javascript file [closed]

I want to change an element color on my page depending on the view's pagination. If i click to previous my div will be green, if i clicked on next my item will be red. I created a view in Drupal. I ...
0
votes
0answers
37 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
19 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
39 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
26 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
31 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
26 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
31 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
26 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
55 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
6 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
40 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
39 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
46 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
55 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
46 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
19 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
40 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
19 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
50 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
75 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
76 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
39 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
62 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
37 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
31 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
81 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
242 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
75 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
59 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
105 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 ...
1
vote
0answers
33 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
58 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
78 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
35 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
56 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 ...
1
vote
2answers
130 views

drupalSettings object not showing for anonymous users. core/drupalSettings is added as a library dependency

I'm stumped on this one. I’m having an issue where the drupalSettings object is empty when not logged in. Works fine when I am authenticated. - core/drupalSettings is in theme’s *.libraries.yml file. ...
0
votes
1answer
105 views

Prevent JS code to be called more than once? ( "once and for all' behavior-attached functions ) [duplicate]

this jquery code works fine (demo codepen ): https://codepen.io/matoeil/pen/XxapEL jquery var $exposed_form=$('.views-exposed-form').clone(); $exposed_form.prependTo('.pagerer-right-pane'); html &...
0
votes
1answer
39 views

Invoke javascript in hook [closed]

I have create a hook to alter page funcionality. It's posible invoke javascript function in hook. I test this function but i had this error --> Call to undefined function alert() ...
0
votes
1answer
33 views

How can I toggle required field?

Using Drupal 7. I'm trying to toggle required field based on the click of a radio button. I already tried the proposed solution in this post but it did not work. Here is my code: $(context)...
1
vote
1answer
44 views

Error 404 when upload image in profile installation

I am installing a custom distribution, I have created a form: my_distribution.install: /** * Implements hook_install_tasks(). */ function my_distribution_install_tasks(&$install_state) { $...
-1
votes
1answer
23 views

Load module config into Javascript from a different module

I have two Drupal modules. One is a shared module that provides a JavaScript library. The second is a module that builds a form which uses that library. Lets call them modlib and modform. They've ...
0
votes
1answer
58 views

how to post an article by jquery using REST service of Drupal?

i want to create an article by rest services of drupal ? as given in the documentation on Drupal Post docs link but it gives an error Reference error : Drupal is not defined in the following ...
1
vote
1answer
51 views

Show and require field if birthday (date field) is less than 18 years old

I have a field that should be visible and required if the user selects a date that would make them less than 18 years old. If they are over 18, the field should be hidden and not required. Right now, ...
0
votes
1answer
161 views

Set custom timer for Slick slideshow based on field value

I have a Slick slideshow. My nodes have a Timer field. Right now, I am setting the time of the slick slide like so: Drupal.behaviors.mrpeanut = { attach: function (context, settings) { var $...
1
vote
1answer
237 views

Capturing keyup event (JavaScript) from Drupal editors (CKeditor)

I maintain the Textfield Counter module. An issue was raised that the module does not work for textareas with CKEditor enabled. I need to catch a keyup event from editors, or even just the CKEditor ...