Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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

0
votes
0answers
18 views

Failed to load popup dialog with in views

I am using Drupal 8.6.1 with the 8.x-1.0-alpha2 Footable module and the core dialog. What I did so far: Install the Footable module. Download the most recent 3.x.x version of the FooTable jQuery ...
0
votes
0answers
22 views

Sending ajax message using jQuery

I am using better exposed filters on my view and I need functionality, so that a second click on the same filter would reset filtering at all and give back all results, sadly I didn't find a solution ...
1
vote
2answers
86 views

drupalSettings object not showing for anonymous users. core/drupalSettings is added as a library dependency

I'm stumped on this one. I’m having an issue where the drupalSettings object is empty when not logged in. Works fine when I am authenticated. - core/drupalSettings is in theme’s *.libraries.yml file. ...
0
votes
1answer
23 views

Prevent JS code to be called more than once? ( "once and for all' behavior-attached functions ) [duplicate]

this jquery code works fine (demo codepen ): https://codepen.io/matoeil/pen/XxapEL jquery var $exposed_form=$('.views-exposed-form').clone(); $exposed_form.prependTo('.pagerer-right-pane'); html &...
0
votes
0answers
14 views

React/GraphQL - Issues fetching user relationship data

I'm using GatsbyJS, gatsby-source-plugin and Drupal 8. Using http://localhost:8000/___graphql playground, I'm able to successfully query my drupal data. Query : { allUserUser { edges { ...
0
votes
1answer
30 views

Invoke javascript in hook [closed]

I have create a hook to alter page funcionality. It's posible invoke javascript function in hook. I test this function but i had this error --> Call to undefined function alert() ...
0
votes
1answer
21 views

How can I toggle required field?

Using Drupal 7. I'm trying to toggle required field based on the click of a radio button. I already tried the proposed solution in this post but it did not work. Here is my code: $(context)...
0
votes
1answer
23 views

Error 404 when upload image in profile installation

I am installing a custom distribution, I have created a form: my_distribution.install: /** * Implements hook_install_tasks(). */ function my_distribution_install_tasks(&$install_state) { $...
-1
votes
1answer
23 views

Load module config into Javascript from a different module

I have two Drupal modules. One is a shared module that provides a JavaScript library. The second is a module that builds a form which uses that library. Lets call them modlib and modform. They've ...
0
votes
1answer
30 views

how to post an article by jquery using REST service of Drupal?

i want to create an article by rest services of drupal ? as given in the documentation on Drupal Post docs link but it gives an error Reference error : Drupal is not defined in the following ...
1
vote
1answer
38 views

Show and require field if birthday (date field) is less than 18 years old

I have a field that should be visible and required if the user selects a date that would make them less than 18 years old. If they are over 18, the field should be hidden and not required. Right now, ...
0
votes
0answers
25 views

How do I print a field in a template to active JavaScript code?

I have a problem that maybe you can help me solve. I have created a program in html and javascript so that, from the title of a film and the year of production, I show the movie's note in several ...
0
votes
1answer
53 views

Set custom timer for Slick slideshow based on field value

I have a Slick slideshow. My nodes have a Timer field. Right now, I am setting the time of the slick slide like so: Drupal.behaviors.mrpeanut = { attach: function (context, settings) { var $...
0
votes
0answers
30 views

How can I save DOM element changes from jquery, to the database on form submission

I've done this at least once before, but I can't find where I did it. I have a CiviCRM form which I am running calculations on and editing the DOM with the new values. The problem is that the DOM ...
1
vote
1answer
32 views

Capturing keyup event (JavaScript) from Drupal editors (CKeditor)

I maintain the Textfield Counter module. An issue was raised that the module does not work for textareas with CKEditor enabled. I need to catch a keyup event from editors, or even just the CKEditor ...
1
vote
1answer
35 views

TypeError: $.ui and $element.dialog is undefined

I have been handed a site to work on. It's on 8.5.1. The site was working. However, I cannot make changes on certain configs. For example, the dialog boxes for the views do not open anymore. I keep ...
0
votes
0answers
11 views

enlarge buttons on field stepper widget

I am using the field stepper module to add plus/minus buttons to an integer field. The problem is that up/down images are way too small on phones. So far I have not been able to figure out how to ...
0
votes
1answer
18 views

Drupal EU Cookie Compliance module conflict with theme JQuery

When I first installed the module, it'd only appear in admin pages. After some investigation, I discovered the cause was some sort of conflict with my themes jquery: jquery-1.11.2.min.js. If I ...
0
votes
1answer
35 views

How can I add jQuery to DOM element through drupal.behaviours?

On my site on the navigation panel I have a dropdown language switcher. (Dropdown Language Switcher module). I need to modify the js file and show the message to the user after he switched the ...
-1
votes
1answer
32 views

Unable to pass the value from .module file to JS using the implementation given below

.module file function taxonomy_fancybox_menu(){ $items['fetch-popup-markup-data/%'] = array( 'title' => 'Store markup', 'page callback' => 'ajax_fetch_markup_popup_data', 'page ...
0
votes
0answers
22 views

How to get the list of aggregated javascript files?

I have a use case where I want to create a map file for aggregated JavaScript files. How can I programmatically get the list of aggregated JavaScript files? I am using Drupal core aggregation.
0
votes
0answers
19 views

Call a Javascript function in a template from a controller

I'm trying to call a JavaScript function in a template from a controller. This is the JavaScript code I am using. <script type="text/javascript"> $('.pdfBtn').on('click', downloadPdf); ...
0
votes
1answer
76 views

Script Errors: $(…).once is not a function

This is driving me nuts. For some reason the jquery.once.js file appears to not be loading randomly, breaking various other scripts. The page source clearly shows the jquery.once.js file being loaded. ...
0
votes
0answers
41 views

How come my view block is not loading using ajax?

We have a view, myview, that has an exposed filter title (text input). The view has Exposed form in block:Yes and so we load it onto the page under admin/structure/block. The block has a machine name ...
0
votes
1answer
51 views

Add a CSS file and a JS file to your Drupal application directory [closed]

I desire to add two files, one for CSS, one for JS, to be used in my application globally (without being dependent in any theme; contrib or core); I can add these with Bash (permissions changed to ...
1
vote
1answer
34 views

Numbering rows of a table-view

New views are usually formatted as an Unformatted list. I could change the format to HTML list and choose between ul or ol. But as I use the DraggableViews module, I have to format my view as a Table ...
-1
votes
1answer
61 views

Drag and drop nodes in a node list (to later use that sorting inside a view) [closed]

Under example.com/en/admin/content I show all site content filtered by content type and then I get a list of all nodes from that content type. The nodes will appear in some sorting (usually date). ...
1
vote
2answers
177 views

Why does JavaScript attached in a widgets render array return the variable value from only the first widget added

I have a custom field type called signature_field. It invokes a JS file and has its own custom template. I pass a variable to both the JS file and template called $text_area_id. In Drupal if I add ...
0
votes
1answer
25 views

Add JavaScript and css to page with nodes only if there is no tag in any of the nodes

I wrote a module that adds javascript and css to a page with nodes of type 'rower', now I need to add javascript and css to the page only if there is no tag with id == 1503 in any of the nodes. I ...
-1
votes
1answer
40 views

Custom Jquery for Entity reference form

How do I add Custom Jquery On-click event on a checkbox which is inside an Entity reference form? In the below screenshot, "Study" is the Parent node. "Demographics", "Biological collections", etc. ...
0
votes
1answer
69 views

How do I use an older jQuery version?

Drupal 8.5 requires jQuery 3, which has some site breaking features. I would rather like to use version 2.2.4. I have tried the libraries-override approach suggested in How do I use a jQuery version ...
1
vote
1answer
152 views

on('load') is not working with jQuery 3?

I used to use the following function to load a video in the background (jquery 2.2.4): function getVideo() { if ( $('video').length ) { $('video').each(function() { if (...
0
votes
0answers
16 views

How to render an AjaxResponse manually? [duplicate]

I have a Drupal 8 form within an AjaxResponse that I want to manually invoke from a JavaScript file. What is the best way to do this? Will the jQuery load() function work?
0
votes
0answers
22 views

How can I render a modal dialog? [duplicate]

I'm trying to render a Drupal 8 modal dialog form through JavaScript, so it can appear on multiple pages across my site. In the controller class, I create an AjaxResponse object with an ...
0
votes
1answer
89 views

How do I render a form with JavaScript?

I'm trying to render a Drupal 8 modal dialog form through JavaScript, so it can appear on multiple pages across my site. In the controller class, I create an AjaxResponse object with an ...
0
votes
0answers
40 views

How to access an Ajax callback return value?

First a confession: I did not write the JavaScript reproduced below. Unfortunately, I am a rookie JavaScripter, and this script was scavenged from another project and slightly adapted by me. The ...
-2
votes
1answer
18 views

Using the powr.io countdown plugin

So I am trying to use the powr.io countdown plugin and it says I should simply have to paste their tag and tag into the body of a Drupal body field and it should work. But it is only spitting out ...
0
votes
0answers
20 views

How to use Drupal.displace inside Drupal.behaviors

I want to scroll down the page at page load time to bring a feature that might be below the fold into the viewport. Script works fine for anonymous, but for authenticated user, Toolbar module overlays ...
0
votes
1answer
29 views

Prevent Quick Editing on certain DOM elements

I want to enable quick edit within a block which contains some JS libraries (such as slick). As slick changes the DOM, when I use quick edit it saves this altered DOM and then the slick library doesn'...
0
votes
0answers
10 views

Trying to apply a modal to each item in a menu

I am trying to assign a ctools modal to each link in the main menu, with the goal being putting these links into a popup. I tried to figure out a way to do this using a hook, but none of the hooks I ...
0
votes
0answers
27 views

$ is not defined [duplicate]

I am having hard time trying to make $ work with my javascript. This is the line of code I am using. If i use jQuery, it works as expected but if I use $, it says $ is not defined. Any advices? if (...
0
votes
0answers
21 views

JS not completely working for anonymous

some of my jquery not isn't working when the user is not connected, I have this : Drupal.behaviors.basic = { attach: function (context, settings) { (function($) { $(window)....
0
votes
1answer
234 views

Why does js click function run multiple times?

I'm creating some accordion functionality for fields and paragraphs using a combination of twig templates and a custom JavaScript file. Everything prints as expected and the basic accordion ...
-2
votes
1answer
78 views

Autoload next page while scrolling to the bottom [closed]

I am looking for a way to automatically load the next article once a reader has scrolled to the bottom of the page. Something similar to what this wordpress plugin is doing. So I understand that the ...
0
votes
1answer
34 views

Register form breaks after changing submit button value with jQuery

I need to change the submit button value (text) based on the selection made in a certain register form field. I accomplished this by using jQuery: (function ($) { $(function() { $("#edit-field-...
3
votes
2answers
327 views

Cannot update checkbox with services

I have been trying several configurations for trying to update a user account checkbox to uncheck it, with no success. I have been able to check it without issue. updateCharType = function (token) { ...
0
votes
0answers
12 views

jcarousel loads empty boxes in footer

I have a problem, using: jcarousel-7.x-2.7 jCarousel is working just fine when it is on page, but when I want to put it in the footer, seems like the js is not working. there are no pictures when on ...
1
vote
1answer
14 views

jQuery transition not run on anon page

I am running Drupal 8.5.5 and am running into a problem. It seems for anonymous users jQuery is not loading a library that it would when I am logged in as admin. I tried to understand why that is but ...
1
vote
0answers
85 views

can't load JavaScript using hook_page_attachments() [closed]

Here my module file I did exactly what the documentation https://www.drupal.org/docs/8/creating-custom-modules/adding-stylesheets-css-and-javascript-js-to-a-drupal-8-module say for declaring js files ...
0
votes
0answers
22 views

Conditional completion message content using JavaScript and PHP code is not working

In my Drupal commerce site (Using DRUPAL 7 and Commerce 1.x), I am trying to create a custom “Checkout complete” page based on the chosen payment method. Depending on the method chosen, the user will ...