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

Questions tagged [javascript]

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

-3
votes
0answers
30 views

Uncaught TypeError: Cannot read property 'namespace' of undefined [on hold]

As we are using the DRUPAL-8, I need help. How to remove out this error, that is display in the console. Any help?
0
votes
1answer
30 views

Slide effect with JQuery

I'm not very good with Javascript/Jquery, and I don't understand something. I display a full size image when the user arrives for the first time on the homepage. If the user scrolls, the image ...
0
votes
1answer
19 views

Using JCF with dynamic forms

I want to use Javascript Custom Forms (JCF) to get more attractive and consistent looking forms on my Drupal 7 site. I've got it working to a degree, however when the form changes with AJAX, the new ...
2
votes
1answer
16 views

Override one line in core tabelselect jQuery behavior so custom checkboxes aren't affected

I have created a custom table using a Form API tableselect element, and within my table, I have embedded a checkbox form element that is checked based on an entity field (see here for details). The ...
-2
votes
0answers
30 views

How do I fix these errors?

I am facing the below errors while trying to add a block inside a region from /admin/structure/block. It is giving a Javascript warning and errors. Please help me resolve this error. I am not sure ...
0
votes
0answers
15 views

How can I run behaviors inline in a node body text?

I realise its not recommended but for fun and experimentation i want to edit/run custom inline js wrapped in a drupal behaviour from CKEditor. Im using Drupal 8.6 and bootstrap theme, which loads ...
0
votes
0answers
10 views

How to modify drupalSettings JavaScript in an Event?

I have a UserLogin event subscriber. I want this subscriber to output a variable from marketing tracking purposes to Javascript, however, I don't see how I could accomplish this, as the Event ...
0
votes
1answer
26 views

create new image style using javascript

I am using fancybox JS library for creating a slideshow from a custom bloc with a multivalue image field. it works but the images on the slideshow are small because a style have been applied to the ...
-1
votes
1answer
45 views

jQuery on Twig Template [duplicate]

I am trying to create a basic jQuery function on my twig template but I can't seem to get it to work. Can someone please help me!? My Twig File is as follows: {% block javascripts %} {#if you ...
1
vote
1answer
19 views

Views switches to another view on apply or any change

When I'm working on a block display in Views on Drupal 7, and hit the "Apply" button, I'm taken to the master (or first view), instead of staying on the block display that I'm working on. How do I ...
1
vote
1answer
38 views

What's the correct way to pass variables to the JavaScript of a custom CKEditor plugin?

I saw that we can pass values to our JavaScript using drupalSettings. However, this is for Drupal custom module JavaScript files. Since a CKEditor plugin file is already attached/loaded in a different ...
0
votes
0answers
19 views

Add binding to “keyup” or “input” to an autocomplete textfield

I have an autocomplete textfield with an #ajax callback on autocompleteclose: $form['myfield-container'] = array( '#type' => 'container', '#attributes' => array( 'class' => array( ...
2
votes
1answer
44 views

What's the difference between drupalSettings and settings parameter in behaviors?

When having the need to pass settings or parameters from PHP to JavaScript, i always used to do so according to a blog post from Acquia - create a dependency to drupalSettings, attach the settings on ...
-1
votes
1answer
40 views

How to apply the page-hiding snippet for Google Optimize?

I'm trying to use Google Optimize on a Drupal 8 site through Google Tag Manager. I have set up the tags in Google Tag Manager through Google's UI and used the Google Tag Manager module to add the ...
1
vote
0answers
25 views

Adding an Attribute to a Script Tag Before Src

I'm working with CloudFlare and have identified a script that needs the data-cfasync=“false” attribute applied so CF doesn't touch it. This script is defined in a library in a custom module. my-...
0
votes
2answers
55 views

adding js and css to custom templates

i created a custom module, which renderes a custom template. i followed this tutorial now basically i want to add, bootstrap, jquery, and some custom stling and scripts, I read this article, ...
0
votes
1answer
25 views

Off canvas dialog using a button

I am trying to adapt the relatively new off canvas dialog introduced in Drupal 8.5. It is suggested to use it with the Drupal Form-API and a link element like this: $form['off_canvas'] = [ '#title'...
1
vote
1answer
29 views

Is the AJAX from image fields and multi-line fields breaking my JavaScript?

We have added tooltips to our node form using this method: https://inclusive-components.design/tooltips-toggletips/ It includes a JavaScript/jQuery snippet that works perfectly except... If the ...
0
votes
1answer
22 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
23 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
97 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
28 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
23 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
31 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
25 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)...
1
vote
1answer
40 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
37 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
44 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
71 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
43 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
107 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
51 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
39 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
40 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
28 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
21 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); ...
1
vote
1answer
157 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
49 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
39 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
87 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
181 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
28 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
43 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
110 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
279 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 (...