Questions tagged [javascript]
Use it for questions about JavaScript code that is very specific for Drupal.
3,118
questions
0
votes
0
answers
26
views
Manipulate the DOM with jQuery just before the page loads
Because of accesibility tests i need to manipulate the html of my page just before it loads completely. I dont want to manipulate contrib modules i am using, so i need to do it with jQuery.
In fact, i ...
1
vote
2
answers
32
views
Make views output more dynamic with knockout.js or other similar framework?
I am currently experimenting with knockout.js so i can make views output more dynamic.
I know React and angular among other newer frameworks are recommended but i do not want to create single page ...
0
votes
1
answer
36
views
Is there a way to use jQuery?
I heard Drupal 10 will no longer support jQuery out-of-the-box.
Is there a way to use jQuery in Drupal 10?
My guess would be that adding jQuery to a module's composer.json file would allow jQuery code ...
-2
votes
0
answers
17
views
Using EJS value in twig function
I'm using the Flyout module for my drupal commerce.
I'd like to use this syntaxe <%- orderItem.purchased_entity.product_id %> inside my twig function {{ getMediaUrl(THE_ID) }}
How can I mix both ...
-1
votes
0
answers
48
views
Select a radio button with Javascript
I have a webform with a set of radio buttons (group).
I need to conditionnaly select one of the radio buttons based on the value of another field. I thought I would use Javascript to achieve this task....
0
votes
1
answer
45
views
Drupal.Behavior fires multiple times while logged in
Some of my Drupal behaviors are firing multiple times while as a logged-in user:
(function myFunction (Drupal) {
"use strict";
Drupal.behaviors.myBehavior = {
attach: function attach ...
0
votes
1
answer
26
views
Behaviors are only executed on some pages, while on others jQuery is not defined
In Drupal 9, I put the following JavaScript code for an image slider and a mobile navigation into a script.js file.
(function($, Drupal, drupalSettings) {
Drupal.behaviors.swiper = {
attach: ...
1
vote
0
answers
7
views
How assign new simple_oauth scopes?
I've a problem with simple_oauth module and scopes, on a D 9.3.x site.
I'm using it to authenticate user in a decoupled front-end in Next.js.
The case is:
A (new) user log-in without roles expect ...
0
votes
1
answer
37
views
Add an event listener to select list
I've attached the following js to an exposed views form field and it works on first page load but when the form is changed (by ajax) it doesn't fire.
I can't quite work out where to add an event ...
0
votes
1
answer
28
views
check if a page has been redirected and then add a class to a certain div
Im using the redirect module to redirect /page/scheduling to /page.
I need to check if the user arrived to a certain page by this redirect.
by checking this i will then add a class to a certain div.
...
0
votes
1
answer
125
views
How upload a file\image via json api?
I'm trying to upload a file or image on a D9 site via json api. The test is namely to upload the user picture on the user entity.
I've been following the documentation or read questions about, but I ...
0
votes
1
answer
43
views
How to refresh and reload (with ajax?) order checkout panes and order calculation independent from commerce cart refresh (e.g. billing address change)
I have following problem:
During checkout, my customer has to fill in his billing address (at least at the first time) to calculate VAT rate and gross price. Further calculation is done via an order ...
0
votes
1
answer
35
views
Overriding Drupal.ajax.prototype is not working
I am trying to override Drupal.ajax.prototype.beforeSend like this:
(function($) {
// In mymodule.js, which appears after ajax.js in the page build
Drupal.ajax.prototype.beforeSend = function(...
0
votes
0
answers
39
views
drupalSettings values lost when accessed from a named function
I have a custom module and in it's .module file I add a value to Drupal settings:
$variables['#attached']['drupalSettings']['my module']['color_body'] = '#dd0000';
I have a named js function and ...
0
votes
0
answers
58
views
Why am I seeing Modernizr JavaScript errors on page load?
When I load pages on our live site (D9), we see these Modernizr errors from contextual links JS, and the contextual links don't appear on the site.
However, Modernizr does appear to be loaded ahead ...
0
votes
0
answers
26
views
How do I get JS event attached to multiple views rows
I am creating a custom views field and need it to have JS attached to it's on click functionality. When I get one views result, it works perfectly, but when I have multiple results, it only attaches ...
0
votes
1
answer
65
views
How can I make this JavaScript code get executed when the BigPipe module is enabled?
I keep struggling with getting JavaScript executed when I need to target a DOM element that is added via the BigPipe module when I'm logged in on my Drupal site.
The following code runs when I'm not ...
0
votes
0
answers
57
views
Drupal Webform REST
I am trying to use Drupal Webform REST.
I got an error "The 'restful post webform_rest_submit' permission is required." on browser console. I have enabled modules and REST resources as ...
0
votes
0
answers
43
views
How do I upgrade jQuery UI?
How do you upgrade jQuery UI in Drupal? Could this be accomplished with Composer or Drush?
0
votes
1
answer
133
views
How do I post a PDF?
I followed these steps to post a PDF file to Drupal.
Enable JSON API to create at admin/config/services/jsonapi
Enable the media POST resource
Media /media/{media}/edit: GET, PATCH, DELETE
/...
4
votes
1
answer
496
views
How do I override a single JavaScript file used in a library?
I am trying to override the Search API autocomplete JavaScript file.
In mytheme.libraries, I added the following lines.
mytheme_autocomplete:
js:
'assets/js/autocomplete.js': { }
In mytheme....
0
votes
0
answers
35
views
Drupal autocomplete jquery UI theming?
I am using search autocomplete which uses the core autocomplete which uses jquery to position the autocomplete form.
The html output is along the lines of
<div class="ui-menu ui-autocomplete ...
0
votes
0
answers
25
views
Submit button of exposed form is not working when it is clicked 2nd time in drupal behaviors
I have created a search form using search API. After clicking on search button search results shows because of search API. Using drupal behaviors I have added a click event on search button, that when ...
0
votes
1
answer
53
views
How can I remove PDF download button?
I am using the pdf_reader module and showing my PDF on the node. Now, I am supposed to hide the download button. For this purpose, I wrote the below javascript file:
jQuery(document).ready(function($) ...
0
votes
0
answers
15
views
Change ajax effect on form
i am making a multistep form, and I would have liked the transition between the steps to be done by sliding from right to left.
The Drupal API offers "fade" and "slide", but the ...
0
votes
0
answers
63
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
1
answer
222
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
1
answer
187
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
1
answer
230
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
1
answer
65
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
1
answer
49
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
1
answer
78
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
0
answers
27
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
1
answer
26
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
1
answer
31
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
0
answers
93
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
1
answer
23
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
1
answer
20
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
0
answers
68
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
1
answer
374
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
2
answers
276
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
1
answer
71
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
1
answer
138
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
1
answer
31
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
1
answer
150
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="{"width":...
0
votes
0
answers
55
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
1
answer
104
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
0
answers
233
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
1
answer
70
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
1
answer
114
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 ...