Questions tagged [javascript]

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

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

How do I get the image path inside a jsonapi response?

I a content type for movies that includes plain text fields, and an image. The field name for the image is field_movie_poster. Using the JSON API, How do I include the image path in the request? If I ...
0
votes
0answers
22 views

JS File's `attach` method not always executed when loaded through block template

We are using a custom barrio sub theme and have some JS files we attach to our template files using the {{ attach_library('custom_barrio/my_js_library') }} line at the top of our twig templates. ...
0
votes
1answer
20 views

Adding Count Up module to custom front page

My end goal is to put several Count Up numbers on my custom front page. But I'm having trouble getting it implemented. First, I installed the Count Up library (https://github.com/inorganik/CountUp.js) ...
0
votes
0answers
25 views

Using TB Megamenu, how to close one submenu when I open another submenu?

I'm building a couple of (Drupal 8.9.13 and Drupal 9 based) sites where I use TB Megamenu megamenu module (https://www.drupal.org/project/tb_megamenu) to create the menu. All is working fine on ...
0
votes
1answer
34 views

Inline Javascript throws an error on drupal_add_js() within an AJAX callback

I am trying to get JavaScript to measure a text field and auto submit at a character limit for an Ajax callback to be validated against a Luhn Algorithm and errors out on failure to validate. I found ...
0
votes
1answer
68 views

jQuery dependency on a custom theme is not adding jQuery?

I know that this question has been asked previously many times but any of the solutions are not working in my case so please, I request if anyone can help me with this situation please provide me ...
1
vote
1answer
66 views

How to use the Vanilla JS version of Drupal Once

Once again i am having a problem with the JS called more than once. the code here transform the select/options of the exposed filters to ul/li. The problem is that the console.log("enter init&...
1
vote
0answers
20 views

Video does not pause automatically when slider change in FlexSlider

I'm using version drupal 7 to create the "slideshow" to display the slideshow of the video, each video is embedded in its own content item. When the user starts to play the video, if the ...
0
votes
0answers
23 views

Is it possible to fire a condition with JavaScript?

I have a webform with radio buttons, where I have conditionals made normally with webform conditions tab setting. Everything works nicely, I have some fields (just text fields) depending on ...
0
votes
1answer
20 views

Radix JavaScript

I am using the Radix Bootstrap Theme and Drupal 9.1.5. I have a Navigation Block with Children (using Bootstrap Dropdown) and some JS in radix_aur_scipt.js. I use that JS to open a Bootstrap Modal ...
-2
votes
2answers
33 views

JS not run with custom module

I have created custom module with drupal 8 after successfully installation on my module run properly with java script but after its not working till now , i have done multiple changes in my module ...
-2
votes
1answer
19 views

Country code in taxonomy shown as flag

I am using ISO 3166-1 alpha-2 codes for countries as a taxonomy in several pages of a given type. When listing those pages in a view, I would like to display the corresponding country flag, rather ...
0
votes
1answer
25 views

Why jquery menu collapse on all pages except front page

I have a Drupal 8 site and them (upgraded from Drupal 7) and the main menu collapses to a button when the page is narrow enough (i.e. on a mobile device). Or at least it is supposed to. I did not ...
0
votes
0answers
21 views

Add external script in head after CSS loading

My question maybe is a little bit strange. I have Drupal 7.x and i need to add in <head> a script to verify my adsense account: <script data-ad-client="ca-pub-xxxxxxxxxxxxx" async ...
1
vote
1answer
71 views

Decoupled login: How do I get the session cookie via JavaScript?

In the Medium app, if you go to the settings tab, you can change some of the settings inside the app. But, if you try to change your email notification settings, it opens up a web browser inside the ...
1
vote
0answers
10 views

Dynamically added params for a link not found when the link is opened with a dialog

I do not know if it has to do with JavaScript/Ajax or with Drupal's dialog modal. Any advice is appreciated. On our project we open several links in a modal. For this the link is rendered in the ...
0
votes
0answers
6 views

overriding core asset ckeditor js to remove ckeditor media edit button

When embeding a media in ckeditor, using the media libray, an edit button is added. Since the editing does not allow to modify custom fields , i would like to remove or hide that edit button. https://...
3
votes
0answers
99 views

Run javascript before Big Pipe

I have a page with multiple blocks loaded asynchronously by the Big Pipe module. I'd like to be able to run some javascript code (in my case, open an ajax popup) immediately after the page is loaded. ...
0
votes
0answers
24 views

plupload upload fails with 500 Error code: 104, message: “Failed to open temporary directory.”

I installed "drupal/plupload": "1.x-dev@dev", "drupal/plupload_widget": "^1.0", "moxiecode/plupload": "^3.1" and configured a upload form ...
0
votes
0answers
18 views

Prepopulate Multi-Part Webform fields from client side javascript API

I am trying to prepopulate fields in a multi-part webform. I make an api call on the first page and stick the response in a hidden field. $.ajax({ type: 'get', url: '/api_helper.php', ...
-3
votes
1answer
107 views

How do I implement clipboard.js?

How to create a "Copy" button to copy a text in Drupal 8? I downloaded the following library in the folder /libraries : https://github.com/zenorocha/clipboard.js Here is my ...
0
votes
0answers
26 views

Attaching a custom javascript library to a Drupal module [duplicate]

I am trying to attach a custom js library to the contact module. Here is the content of my js/custom.js file: function myFunc(){ console.log('hello toto'); } document.addEventListener('click', ...
0
votes
1answer
49 views

Javascript file attached via Drupal behaviours does not work occasionally

I'm facing a weird issue where a JS file attached via the Javascript API does not work properly. I couldn't really pin down why it isn't working by the JS file consists of a few event listeners which ...
0
votes
1answer
43 views

How can I load a JavaScript file only when a page has an element whose class is “test”?

In my develop process, I meet a scenario: I only want to load a JavaScript file when a page has an element whose class is test, so what can I do? How to know a page whether has this element?
0
votes
0answers
12 views

try to hide button with certain class in js file

I've got flags in a paragraph field, I try to hide other flags of the paragraph if one is clicked. Here is the html: <div data-quickedit-entity-id="paragraph/10" class="paragraph ...
0
votes
1answer
24 views

What is the recommended jQuery and jQuery UI version?

What is the recommended version of jQuery and jQuery UI that I should use on a Drupal 7.77 site? I know the latest jQuery version is now 3.5.1, but what is the recommended version for a Drupal 7.77 ...
0
votes
0answers
18 views

Show another page in a modal popup

I'm working on a page that will have a couple links on it that need to show another page in a modal popup. I've used class="use-ajax" to accomplish this in the past. However, I'm making ...
4
votes
1answer
72 views

How to add a js script as type=“module”

How to add type="module" to script added in MODULENAME.libraries.yml when i do: my-library: version: 1.x js: js/App.js: { } I get <script src="/modules/custom/MODULENAME/js/...
1
vote
0answers
27 views

Trigger Jquery after form submission

I'm trying to trigger a javascript function after specific types of form submission on my site, as I want it to do something with the submitted data. I'm much more familiar with D7 than I am D8, and ...
0
votes
1answer
63 views

Drupal 8 Jquery/Ajax Views Arguments

Setup: I have two contextual filters, service area and ID. In my view if I send {service_area}/{id} i get back the OR query, which is what I want. My question is, when I try to use Jquery to return ...
2
votes
1answer
57 views

Why we use dependencies keyword in {theme}libraries.yml ? and not just include the file?

in the {theme}.libraries.yml why we need to declare the jquery js or any other library as a depedency : js: assets/lib/bootstrap-4.0.0-dist/js/bootstrap.js: {} assets/script.js: {} ...
-2
votes
1answer
50 views

How do you add/edit code in Drupal? [closed]

I recently got thrown into a project to fix some problems with a Drupal 7 website for a client despite knowing nothing about it. First of all, is there a way to add my own custom PHP or Javascript ...
0
votes
1answer
42 views

Some #states not working for custom field but do work on identical webform field

I'm working on a project where I'm programmatically cherry picking elements from a webform and then creating a custom form with all sorts of alterations and additions to the "cloned" webform ...
1
vote
0answers
39 views

Form submit event defined with Drupal.behaviors fires several times

I want to react in JavaScript on the submission of a form but whatever I try the function is called three times: (function ($, Drupal) { Drupal.behaviors.xmasEasteregg = { attach: function ...
0
votes
1answer
45 views

Add JS to all webform

I have a Drupal 9 custom theme and would like to attach a JS file on the webform. Adding JS file in themename.libraries.yml does not work. webform: js: theme: js/webform.min.js: {} What ...
0
votes
1answer
31 views

Is there a browser-side validation passed event I can listen for?

Is there a JS event that my own custom code can listen for to determine that client-side / browser validation of a form has passed? i.e. That no messages like this have occurred: "Please fill in ...
0
votes
0answers
29 views

How can I get custom code running at a specific path? [duplicate]

I am trying to add custom javascript to my Drupal 7 site which I need to run on the path /node/add/h5p-content. I have created a custom module (called mods) with the function: function ...
0
votes
0answers
93 views

Custom javascript runs before block loaded

I have two jQuery calls to modify two divs on a page. One works, the other attempts to work, but the block is lazy loaded, likely using BigPipe. This helpful doc page is what I'm referring because it ...
0
votes
0answers
21 views

Getting intermittent AJAX.js error on a Commerce site when changing product variation dropdown menu [duplicate]

We've been trying to troubleshoot this issue for weeks now without luck and am really hoping someone here can help point us in the right direction. We have a D8/Commerce 2 site with a **very ...
0
votes
1answer
52 views

How do I ensure new dependencies added to the info.yml of an existing enabled module are picked up?

I've added dependencies: - core/jquery - core/drupal to mymodule.info.yml (where mymodule is my module name). How do I ensure Drupal "sees" these new dependencies? For example, can I ...
0
votes
1answer
64 views

How can I attach the same library with Javascript multiple times on the same page with different settings?

I have a custom field formatter that attaches a library that includes a javascript file. It uses drupalSettings to pass some values to the script. The first time the field formatter appears on a page, ...
2
votes
1answer
83 views

Ajax submission not working for Webform within a node

I am working with a feature where a newsletter subscription form (Webform with ajax submission and confirmation type is inline) should appear in a node. The node would be showing as a popup and the ...
0
votes
0answers
38 views

Checkbox Form Element: Displaying checkboxes value based on on/off

I have a checkbox form element that uses taxonomy terms via variable_get as #default_value; storing the result. I don't want to overwrite value, I just want the form to render/display checked ...
0
votes
0answers
55 views

How can I render a form via javascript without outputting the entire page markup [duplicate]

I'm trying to load a custom form into a div, but when I do, the entire page markup (menu, header, footer, etc) is being output in the div. Is there a way I can only output the form? This is my ...
2
votes
1answer
120 views

How to attach variables to drupalSettings with ajax?

With the page attachments function, I can easily attach a library or some variables to drupalSettings. Now however, I want to replace some HTML code with ajax AND attach some variables to ...
0
votes
0answers
53 views

How do I pre-fill a image field in a form with javascript

I've got a form which I want to fill with javascript on a button click. This button click retrieves the data via a javascript call. All regular fields are no issue, I just cant seem to be able to pre-...
0
votes
0answers
34 views

How to use ajax without a form? [duplicate]

I'm trying to setup a ajax call with JS but without building a drupal form. Basically it will trigger when the user clicks a specific class element on the page. I've looked through the documentation ...
2
votes
0answers
78 views

How to use non-minified js (e.g. jQuery) for debugging/development?

Background Drupal core contains some 3rd party javascript libraries, among them jQuery. Typically such libraries are available as un-minified and minified versions. A minified js file can have a ...
0
votes
0answers
50 views

javascript code does not execute for authenticated users

Maybe someone of you has already encountered this weird problem that I am having. I have javascript code that runs fine when you are an anonymous user and no longer works when authenticating. The ...
0
votes
0answers
13 views

Add custom param data-cmp-src in drupal_add_js [duplicate]

I added js files in the header of my drupal 7 site by using drupal_add_js as the example below: drupal_add_js(drupal_get_path('theme', 'ims') .'/js/qc2.js', array('group' => JS_THEME, 'scope' => ...

1
2 3 4 5
62