Questions tagged [javascript]
Use it for questions about JavaScript code that is very specific for Drupal.
3,198
questions
0
votes
0
answers
201
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
153
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
626
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
1k
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
113
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
98
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
170
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
587
views
Can I translate a variable using Drupal.t()?
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, I am using this ...
0
votes
1
answer
967
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
366
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
164
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
116
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
118
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
1
answer
101
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
82
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
142
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
31
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
26
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
141
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
742
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
571
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
119
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
219
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
44
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
357
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
118
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
2
answers
439
views
Why does my JS file not get loaded? [closed]
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
1
answer
150
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
186
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
1
answer
233
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?
3
votes
1
answer
98
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 ...
-2
votes
1
answer
60
views
Jquery to move field above the table - changes during page refresh [closed]
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
0
answers
268
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-...
0
votes
0
answers
210
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
1
answer
180
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
1
answer
108
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
0
answers
54
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
1
answer
154
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 ...
1
vote
1
answer
254
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 ...
5
votes
1
answer
274
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
1
answer
2k
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
0
answers
34
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
1
answer
345
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
1
answer
197
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
1
answer
71
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
1
answer
949
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 ...
2
votes
1
answer
1k
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
0
answers
614
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
1
answer
166
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
2
answers
160
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 ...