Questions tagged [javascript]

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

Filter by
Sorted by
Tagged with
0
votes
0answers
35 views

The use of contexts in a Drupal.t() function in Javascript

According to the documentation, we can use contexts with Drupal.t() since Drupal 8. Drupal.t('May', {}, {context: "Long month name"}); works fine, but Drupal.t('May', {}, {context: "...
0
votes
1answer
24 views

Can I translate a variable using jQuery Drupal.t function in Drupal 9?

I am using the REST API in Drupal 9 and am using JavaScript template literals to generate some of the data. For example, to generate a list of products that are pulled from the API this is my code - &...
0
votes
1answer
21 views

Execute a behavior only once per page load

Moving from Dupal 7 to 9, I'm having a problem with javascript behaviors being called multiple times. In the browser console, when I load a page, I'm seeing: process test for [object HTMLDocument] ...
1
vote
2answers
209 views

How can I force user logout from a JavaScript library in a custom module?

I've written a custom module for Drupal 8 to monitor user device location frequently. If a user goes out of an allowed zone boundary, I need to force logging the user out of the website. I created ...
0
votes
1answer
38 views

How to remove addtoany js for a particular node page?

I need to unset addtoany module js for a particular node. For that I have implemented function theme_name_js_alter(&$javascript) { if(\Drupal::service('path.matcher')->isFrontPage()) { ...
0
votes
1answer
20 views

Get client credentials from Simple Oauth module

I am creating user authentification with Drupal 9 + NuxtJS. Using Simple Oauth module and create post requests to oauth/token with data const data = { grant_type: 'password', client_id: '', ...
-3
votes
1answer
63 views

How to track recently viewed nodes using JavaScript on a completely cached website?

I want to make a block of recently viewed nodes on a website which is completely cached using Boost module (it saves a static HTML page for every request on the website). I don't want to disable Boost ...
0
votes
0answers
25 views

Load view form with ajax missing ajax functionality

When clicking an element I get a form which is generated by a view (using https://www.drupal.org/project/editablefields module). The problem is that the ajax functionality of the form is lost (no ajax-...
0
votes
1answer
16 views

Adding theme JS library in custom module

My theme documention.libraries.yml file is defined as follows : global-styling: version: VERSION css: base: styles/dist/styles.css: {} tocbot: js: libraries/tocbot/tocbot.js: {} ...
0
votes
1answer
14 views

Geofield map : add marker on click listener

I've added a google map which I feed thanks to the Geofield module. I'd like to add an onClick event to each marker to have a custom behavior. this is what I've done this far : Drupal.behaviors....
0
votes
0answers
65 views

Save textarea word count programmatically

I'm trying to keep a word count tally on a set of long text fields. As far as I can see, there are several options: Create a view and add php to a custom template that produces the word count. Most ...
0
votes
1answer
20 views

Drupal modal does not render remote forms (Mautic)

I'm trying to embed Mautic forms in my drupal site. I created a controller pointing to '/mautic-form` and in the twig template I have this: <script type="text/javascript" src="//...
0
votes
1answer
17 views

Is there a way to synchronize a webpage from another website into Drupal?

A restaurant has its menu database in Foodpanda. The owner wants that menu to appear in the website. We can manually duplicate all menu courses from FoodPanda to Drupal, upload the same images, etc. ...
1
vote
0answers
41 views

How do I override /libraries/ckeditor-wordcount-plugin/lang/some.js?

I'm using ckwordcount module which basically adds nice max length and counter features to text Fields, and relies on WordCount Plugin for CKEditor Editor. Most of the translations in the plugin lang ...
-2
votes
1answer
179 views

I cannot call a function in another JavaScript file [closed]

I have two JavaScript files on my custom theme. One file has functions that need to be used on the other file. What I have below doesn't work. This is the error I get. Uncaught ReferenceError: test ...
-3
votes
2answers
95 views

can I set multiple JavaScript files on a custom module library?

I created a new module and I need to add multiple JavaScript files to my pageI. Should I create a new library for each file, or is it possible to add multiple JavaScript files on the same library as ...
0
votes
1answer
48 views

How do I make JavaScript behavior run on every page load? [closed]

I don't know how to run my Drupal.behaviours.mybehaviour on every page load. Here's my code example that run only once, when I load the page is no longer run my code, how can I change that from once ...
0
votes
1answer
80 views

Paragraphs removed from graphql schema if not anywhere in content, which causes error for union type

I'm making a headless Drupal site with Gatsby using paragraphs. I'm experienced with Drupal but relatively new with gatsby/graphql. The issue I'm running into is that if our database does not actually ...
0
votes
1answer
28 views

Validation doesn't show an error when the value entered in the field doesn't respect the minimum length

I am using the Field validation module to validate a text field using the Length rule with a minimum length of 1. When the field is left empty, no validation error is shown. Setting the field as ...
2
votes
1answer
74 views

Custom Submit Callback only triggering when Form is Valid when in Dialog

I'm trying to create a node in a dialog with the following link: Enter the title of a registration form or <a class="use-ajax" data-dialog-options="{&quot;width&quot;:...
0
votes
0answers
39 views

Rerun behaviors

In order to output the SearchApiAutoCompleteFormBlock (view) within a modal, we lost the bound JavaScript events on the input. In other words, the DOM element (<div>) for the block was ...
0
votes
1answer
49 views

Why does my JS file not get loaded?

I am a beginner with Drupal. I want to include a JavaScript file using a custom module. I created the .libraries.yml file, hello_world.libraries.yml. hello_world_js: js: js/basic.js: {} ...
0
votes
0answers
108 views

Add custom buttons to TinyMCE editor toolbar

I'm trying to add a custom button to my TinyMCE editor in Wysiwyg on a Drupal 7 install. I've managed to adapt TinyMCE settings to work in my custom module, like so: function ...
0
votes
1answer
53 views

Adding Javascript within a hook_entity_type_presave() hook

I'm trying to add Javascript into a hook_entity_type_presave() hook, but it's not firing. Is it possible to add within this hook? I've attempted to with no success -- my code is below -- and this ...
0
votes
1answer
91 views

What is the correct way to load a JavaScript library?

I am trying to display form data as a line chart. I am running Drupal 9 in Lando. I am using Charts 5.0.x w/ the Highcharts submodule. I installed the Highcharts JS library using composer. This is ...
0
votes
1answer
84 views

how to add javascript to an article? [closed]

just installed a stock Drupal 9.2.2 core, trying to create an article with the /node/add/article editor, how do i add javascript to the article?
1
vote
0answers
41 views

Correctly configure the JavaScript tools

I am trying to configure eslint for Drupal in PHPStorm, and it's really confusing. For example, I have installed the node dependencies that comes in the web/core/package.json file. In PHPStorm, in the ...
-1
votes
1answer
52 views

Jquery to move field above the table - changes during page refresh

I have the below jquery code to move a multiselect field and a button above the table. jQuery(document).ready(function($){ $('#views-form-resources-block-1 .form-item-ka-types').insertBefore($('#...
0
votes
0answers
91 views

How do I add colorbox-load classes and attributes to links that come from an svg image?

I have SVG images that are added to nodes via svg_image_field module. They have internal links in them /load-parts-ajax/{nid}. The path leads to a pop-up page view of content with this path /load-...
2
votes
0answers
69 views

How do I safely mark the listener as passive and keep it working? [closed]

I'm trying to optimize the website performance according to the Google PageSpeed recommendations. One of the advices is to set touch and wheel event listeners as passive, which is shown for the core/...
0
votes
0answers
48 views

Form with ajax and javascript problem

I re-create the question with more accurate data (Original question Form with ajax and javascript problem). I have a button in my form that generates a fieldset via ajax. When I try to track this ...
1
vote
1answer
81 views

Why isn't the Highcharts library, defined from a custom module, loaded in every page?

I am running Drupal 9.1.7 on lando on a Mac. I am writing a custom module and I want to include the Highcharts library. The .libraries.yml file looks like this. stats_degrees: js: https://code....
1
vote
1answer
88 views

Somehow subscribe/react to addMessage

I'm trying to find an event that I can subscribe to for the method addMessage. I need to trigger some code everytime a status message is added. On reacting to this event, I need to send a variable ...
0
votes
0answers
32 views

Javascript, saving a event state?

So I have a table that has about 10 items listed. When I click on a 'TR', in my javascript code, I have it set where it highlights that particular table row green. This is basically a generated ...
0
votes
1answer
50 views

Underscore JS Not Loading

I am writing code that uses Underscore JS in Drupal 9 that should be loaded from /core/assets/vendor/underscore. I am using Chrome DevTools to see the sources and though jquery, jquery-once, and ...
0
votes
0answers
16 views

Prevent webform from submitting when clicking button in markup component

I have a very complex webform in a Drupal 7 website I've inherited. I have added a markup component which builds a button and added some JS that links this button to trigger a modal window to open. In ...
1
vote
1answer
135 views

Behavior to use .insertAfter() on load + after each ajax call?

So I have a views page that outputs some elements in the grid. And I have a custom block on the page that needs to be inserted between those elements. On load it using .insertAfter() to randomly ...
4
votes
1answer
87 views

How to add an autocomplete field with pure javascript

I'm implementing the javascript library Annotorious which allow to add annotations on an image. My goal is to be able to link content with part of the image select with Annotorious. When we select a ...
0
votes
1answer
704 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
27 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
107 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
1answer
61 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
55 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
295 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
324 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
184 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
1answer
57 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
52 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
87 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
50 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 ...

1
2 3 4 5
62