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
5 views

Get data from one editor field and pass that into another editor field

I have no idea if this is even possible, but I figured I'd ask anyway. I'm working with a site that is on Drupal 8, and long story short, we don't have access to extending nor updating much so any ...
3
votes
0answers
41 views

Is it possible to pass variables as arguments to *.libraries.yml?

Say I have a foo.libraries.yml defined as so: external.bc.js: version: 1.x js: //players.brightcove.net/{{variable here}}/{{variable here}}/index.min.js: { type: external, minified: true} ...
-3
votes
0answers
13 views

Split input field in multiple fields in Drupal 8 webform [closed]

For a project I'm working on, there should be this form element: Is there a way to "split" the input field in different fields and make sure it's editable in this layout?
-3
votes
0answers
40 views

Uncaught TypeError: $(…).once is not a function

I am having this issue on drupal 7 and can't find any solutions. Uncaught TypeError: $(...).once is not a function at Object.attach (eu_cookie_compliance.js?q5vyka:18) at Object. (drupal.js?...
0
votes
1answer
38 views

How to load a internal page content within div? [closed]

I have following code in a basic page on drupal 7 <h2 id="tabs">Test Title</h2> <!-- Nav tabs --> <ul class="nav nav-tabs"> <li class="active"><a href="content/test" ...
0
votes
1answer
35 views

How to log to console when in a Drupal attach behavior?

I'm using Drupal 7. I have the following code that tries to log to the console: function mymodule_get_jquery() { $jquery = <<<JAVASCRIPT console.log("here"); (function($) { ...
-2
votes
0answers
19 views

Twig and Javascript [duplicate]

I can not use twig tags as "for" for example in js used in twig. Can anybody help me? {% block javascripts %} <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/...
-3
votes
0answers
65 views

how add html, css, and javascript in a basic page in drupal 8 [closed]

i need to have the following added to a basic page in a drupal 8 site. Problem is how could i copy paste these three files html, css, and javascript, in a single page of content type basic page in ...
-2
votes
0answers
23 views

$form['#validate'] is not being called

All, I am using modal popup with the javascript in drupal. So when I click on the submit button, I am able to see modal popup, but not the validation. I am able to see the validation after clicking ...
6
votes
1answer
89 views

Understanding State of JS in Drupal

I have a simple contributed module that I have written. It has pretty basic javascript. I decided to clean it up and write it in vanilla js, removing jQuery since that seems to be the direction we're ...
0
votes
0answers
35 views

Variables in drupalSettings get cached

I am using the value of a field in the page as a variable. I am trying to use it in the page somewhere else but I think that there is a problem with the cache because the value is sometimes available ...
1
vote
2answers
40 views

Using #states in a form with checkboxes

I would like when a client check one of the checkboxes, a text field appeares. Example: if he clicks on 3 checkboxes, all the textfields of the 3 show off. My #checkboxes : $form['input']['...
0
votes
0answers
32 views

How can you pass the value of a variable from drupalSettings to an iframe in the same page?

I have a variable in Drupal settings which gets its value from php. (function ($, Drupal, drupalSettings) { /** * @namespace */ Drupal.behaviors.pdf_appAccessData = { attach: function (...
0
votes
1answer
52 views

js file in custom module's library is not attached when big pipe is running

I have a custom module, filter_component, that provides a form. In the form I have: $form['#attached']['library'][] = 'filter_component/filter-component'; In filter_component.libraries.yml I have: ...
0
votes
1answer
40 views

drupalSettings value is undefined [duplicate]

I am trying to call a JavaScript function when I click on a button in a form. I have multiple buttons in a for loop and I have attached the library to all those buttons. (Not sure whether this is a ...
0
votes
1answer
45 views

How do I add inline JavaScript to the footer? [duplicate]

I want to add third-party JavaScript code at bottom of the every page. I build an module and I am able to add the JavaScript on the head tag, instead of footer. I am using the following code. ...
1
vote
1answer
22 views

Override contrib Disqus behavior settings

I want to override a contrib module's library setting that is being attached to page using hook_js_settings_alter(). But, I am unable to change the setting that is being called in js. Here is the ...
2
votes
1answer
114 views

How do I render a submit button so that it's disabled initially and enabled by JavaScript?

We have a form that includes a React JS frontend component. The component collects some required information, which the React component then supplies to the backend by populating a hidden form field. ...
1
vote
1answer
58 views

How to create a select drop down that opens a URL?

I have a select drop down. When the user selects a value from the drop down, the user will then click on a button and based on what the user has selected it will open a url in a new tab. While this is ...
0
votes
1answer
19 views

Override a file from the parent theme

Adding in the child theme a CSS file with the same name as the parent theme CSS file overrides the parent file. It doesn't seem to work JavaScript files. How can I override a JavaScript file loaded ...
0
votes
0answers
45 views

How to Resolve CORB Issue using Drupal Docker Container

I'm running the latest version of the Drupal docker container. I'm trying to make a GET API call via Javascript and I'm receiving back CORB (cross-origin-read-blocking) errors in the Console when ...
-2
votes
1answer
31 views

Fetch live data (json) and make accessible to javascript or javascript library (React)

I've built a service that returns data from an external API (in JSON format). I do not want to render that directly onto a page or store it in a node but rather make it accessible to javascript/...
1
vote
1answer
37 views

How to prevent drupalSettings to sort settings object

I attach drupalSettings in a preprocess hook using code similar to the following one. $settings = [ 'bcd' => 'BCD', 'abc' => 'ABC' ]; $variables['#attached']['drupalSettings']['options'] =...
-1
votes
1answer
65 views

Add a css class to the active link then remove it when becomes inactive

I know this question might not fit here but I am afraid that I am doing something wrong related to Drupal since it is my first time with JS code and its implementation into Drupal core. I have placed ...
0
votes
0answers
28 views

How to wrap Paragraph fieldgroup horizontally

I want to display a few fieldgroups inside of a Paragraph side-by-side horizontally when in node edit form. I gave each fieldgroup the class .popular in the GUI in manage form display. The fieldgroup ...
0
votes
2answers
115 views

Select all checkboxes of an entity reference field on creating a node

Drupal 8.7.x For one of my content types I have an entity reference field referencing a taxonomy vocabulary. I have a lot of terms in this vocabulary which makes it tedious to check all the ...
0
votes
1answer
17 views

How to use Views Photos Grid module with custom minimal theme

I use Views Photos Grid module and it shows the results correctly with Stark theme. However, it shows all the images stacked in only place in my custom theme. I do include modules css and js files: &...
0
votes
1answer
41 views

CSS and JS 404 On Admin Site Only - New Install [closed]

This is a new server build... me@server:~$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 18.04.3 LTS Release: 18.04 Codename: bionic Apache... me@...
0
votes
1answer
22 views

Why does not the preview of the loaded image appear?

When I load an image into a Drupal 8 form, JS errors appear in the console and the file link is not displayed. I have a limit of 10 MB per file in Drupal. If I load an image of 1 MB or less, it works. ...
0
votes
1answer
26 views

Javascript not working in body field. Using Full HTML

I have created a basic page. Inserted the following tripAdvisor your rating widget code in that which contains some javascript. Used Full HTML formatting. But instead of displaying the rating widget ...
0
votes
0answers
17 views

Autoplay variable in settingforms

I am working on slider module in Drupal 8 using jQuery library. But I have a little problem. I use default option/plugin of jQuery library like "autoplay": {"enabled": true, "direction": "ltr"} in ...
0
votes
0answers
30 views

How to attach behaviors after an AJAX load in a view

I am trying to add a reset button to some exposed filters for my view. My code: (function ($, Drupal) { Drupal.behaviors.blog_filters = { attach: function (context, settings) { var ...
0
votes
1answer
166 views

Using a sweet alert with preventDefault()

I have an event on a form submit. I set preventDefault() to stop the form submitting then pop a sweetalert with a confirm callback. If they decide to go ahead is POSTS the form to Drupal. The issue ...
0
votes
1answer
223 views

DrupalSettings are not passing the values from block to js?

I have been trying to pass the variables from block to jquery. In Block.php, return [ '#theme' => 'block--exampleblock', '#value' => 'test', '#attached' => [ '...
0
votes
0answers
63 views

Get field value in viewer.js file (from pdf.js)

I created PDF files protected with password. They are uploaded to Drupal and the password is saved in a field pdf_password in Drupal. I would like the PDF to open them with pdf.js without having to ...
-1
votes
2answers
69 views

JavaScript dependencies for a specific block or page [duplicate]

I am migrating a Drupal 7 site to Drupal 8. I have a custom block (visible only on the home page) that has some tabs on it. Currently, the tabs are implemented using jQuery UI tabs and it would be ...
0
votes
1answer
41 views

How we can get the value entered in search API autocomplete field in jQuery?

I got a requirement to send the search text to GTM for tracking purpose. I have a field which is from search api autocomplete module. I am not getting the value in jQuery on click of submit button. I ...
1
vote
1answer
95 views

Add custom attribute to an external JS script

It's not really clear how to add custom attributes when adding an external JS script to the page. Currently I have this code: drupal_add_js('https://code.jquery.com/jquery-3.4.1.js', array('type' =&...
1
vote
0answers
165 views

How do I add a script just above the closing body tag?

How do I add a script on Drupal 8 site/app just above closing body tag? Vendor provided some JS in the following form: <script> ... code </script> Asked me to place immediately ...
0
votes
0answers
752 views

How can I solve this Uncaught TypeError: $elements.tooltip is not a function?

Problem The tooltips don't work. I have the following error message in Chrome's JS console. jquery.min.js?v=3.2.1:2 Uncaught TypeError: $elements.tooltip is not a function at Object....
0
votes
1answer
30 views

Drupal.behaviors js code executes mutiple times (depends on active modules)

I have two almost similar websites (one was a test project) and second one is more like final version. On both of them i have quite simple custom module with js and on first web site it works fine, ...
-1
votes
3answers
217 views

call a custom JS function once [closed]

I understand once() can be used on a jquery selector method to make sure it is triggered only once. How to do the same with custom functions? My function wakeUpAndRemember is called 5 times which is ...
0
votes
0answers
26 views

AJAX View not working with Webpack

I have a Drupal 8 website running in a Docker environment. I have an AJAX-enabled View that works perfectly fine when I am running my website on the URL provided by my Docker setup (http://back.d8....
0
votes
1answer
80 views

How can I call custom javascript on successful webform submissions through hook_form_alter?

I have some custom js code which should be executed after successful webform's submission. JS Code : jQuery('document').ready(function(){ form_submit_telium(); }); below approaches, I already ...
-2
votes
1answer
52 views

Using once method on event listener [closed]

In the series of problems I have with the usage of once method, I wonder how I can refactor simply that code with the once method and be able to toggle local storage on a set of clickable elts: (...
0
votes
0answers
26 views

Leaflet version not detected

I have a drupal 7 site, competely upd to date. Installed Leaflet en put the leaflet libarie (unzipped) (https://leafletjs.com/) (1.5.1) in the sites/all/libraries/leaflet. However, in the ...
0
votes
1answer
45 views

Add js with custom type

How can i add a script file with type='module', like this : <script src="site/test/test/index.js" type="module"></script> I tried with : drupal_add_js(drupal_get_path('module', '...
0
votes
1answer
73 views

Blocking JS from being executed more than once

JS lines of code are often executed more than once. How can this ( annoying ) behaviour be blocked? (function ($, Drupal) { 'use strict'; Drupal.behaviors.recherche = { attach: function (...
0
votes
0answers
55 views

Drupal.behaviors when no AJAX is involved?

I would think there would already be a straight forward answer to my very simple question however I couldn't find it. Forgive me if this is a duplicate. My question is: If I only want my jQuery to ...
0
votes
1answer
71 views

How to get my button in a dialog click?

I have added the following JS to a node form, it clones the submit button but clicking it inside the dialog (which does show up) doesn't submit the form in the browser, just nothing happens when the ...

1 2 3 4 5 61