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.

0
votes
0answers
23 views

How to integrate javascript API for office? [on hold]

I have a requirement that I need to use Office 365 excel as my data source. But I am not able to connect with the Javascript Office APIs. I added like below in libraries.yml: excel.data: version: ...
0
votes
1answer
30 views

How do I implement a one page navigation with anchors?

So the specific functionality I'm looking for is a link on one page (e.g. drupalsite/home) leading directly to a specific section of another page (e.g. a section on drupalsite/otherpage). I believe ...
0
votes
1answer
16 views

Change input value on click when there is more than one paragraph

There are two fields on my paragraph. A number field A text field I want to change the value of the text field when I click on the number field. Here's my script so far which is only good on ...
0
votes
0answers
8 views

Get path of advanced aggregator files

Is there an easy way to get the files? I would like to send the aggregated files over to a debugging service but the drupal_get_js() is not supported anymore. Any other way to fetch them?
0
votes
1answer
32 views

AJAX SettingsCommand Usage

Class Documentation: SettingsCommand I'm trying to figure out how to use this Ajax Command correctly. I must be confused from the documentation, so I'm hoping someone can shed some light where I'm ...
0
votes
1answer
24 views

How do I enable an onclick event in a link on a form?

I am using the following code. $form['test'] = array( '#type' => 'link', '#href' => "javascript:;", '#title' => t('Show'), '#attributes' => array( ...
1
vote
2answers
37 views

Equivalent method or “body onload”

First, I have tried for several hours to weed through the various search results of the keywords above. I've found several things that seem to answer this but they're for D7, one of them from 2012 ...
0
votes
2answers
35 views

How to add javascript with #attached in a node which contains a specific paragraph bundle

I need to attach js in all nodes with a specif paragraph bundle. I know how to do this with drupal_add_js, but i prefer don't use it to prevent cache problems. I am trying with hook preprocess_entity ...
0
votes
1answer
35 views

Slide effect with JQuery [closed]

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
22 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
18 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 ...
0
votes
0answers
22 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
16 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
36 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
61 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
42 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 ...
-1
votes
0answers
21 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
54 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 ...
0
votes
1answer
58 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
29 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
37 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
32 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
27 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
25 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
105 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
40 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
1answer
33 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
27 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
43 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
42 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
48 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
26 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
97 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 $...
1
vote
1answer
159 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
72 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
12 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
52 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
58 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
30 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
24 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
213 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
63 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
45 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
96 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
188 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 ...