Skip to main content

Questions tagged [javascript]

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

Filter by
Sorted by
Tagged with
8 votes
4 answers
13k views

ReferenceError: Drupal is not defined

I am working on a production site, moving settings from a development site for a mobile environment. However, I am receiving the above error. I can not figure out what is causing this error. It does ...
Cameron's user avatar
  • 83
8 votes
1 answer
1k views

what is the difference between using drupal_add_js and ['#attached']

What is the difference between drupal_add_js() and $form['#attached']['js'][] ? When is the purpose of using each of the above functions? (I mean I know that it is used to attached js to say form if ...
harshal's user avatar
  • 4,354
7 votes
2 answers
687 views

Big pipe and behaviors context

I have problem with drupal behaviors and context in combination with big pipe. It seems like context variable sometimes contains same part of page. I have tried: (function ($, Drupal) { Drupal....
marysmech's user avatar
  • 263
7 votes
3 answers
14k views

How do I make a theme require Jquery (for anonymous users)?

I'm creating a theme for D8 called 'herchel'.I'm trying to get this theme to require jquery on all pages (D8 doesn't load Jquery for anonymous users by default) Looking through the what little ...
mherchel's user avatar
  • 293
7 votes
3 answers
10k views

#states visible

The states visible seems to work correct in D7. In D8 I want to test make a field visable if one OR another field have a value. And also when two fields have a value. What I have below works if both ...
paul cappucci's user avatar
7 votes
1 answer
13k views

Add javascript to form by module

i am writing a module in drupal 8. I wish to add a javascript when loading that form. function ajax_example_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) { $...
johnchan's user avatar
  • 371
7 votes
4 answers
8k views

Display view nodes in lightbox?

What would be the best way to show the nodes from a view in a lightbox, triggered by a single image? The idea would be that a nice photo is shown on a frontpage. When users click on it, a view is ...
Bart Braem's user avatar
7 votes
3 answers
2k views

How can I slideDown with #states?

I have a form using "#states" (in the Relation module), and it works, but it kind of jumps around. A nice slideDown would be so much better. How can I do that instead of just making it visible?
user avatar
6 votes
5 answers
14k views

How to properly add inline Javascript?

Now that drupal_add_js(...., 'inline') is no longer possible, how can I inject dynamic Javascript from a custom module's Controller? (I'm trying to upgrade a D6 module with as little refactorings as ...
Nic's user avatar
  • 1,215
6 votes
3 answers
3k 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']['...
StefanYYC's user avatar
6 votes
2 answers
6k views

Call Drupal PHP function from Javascript?

I'm trying to get the content of an article and display it using AJAX by replacing the content of a div with the new article's content. In order to do this I want to make an asynchronous jQuery call ...
user avatar
6 votes
2 answers
3k views

Loading a library only for the front page

I want to load JavaScript only on the home page of my site. I found this preprocess function but I don't know how to customize it for the home page: function mytheme_preprocess_maintenance_page(&$...
Sage's user avatar
  • 2,463
6 votes
2 answers
4k views

Drupal load form with ajax callback in Bootstrap modal

I need to load a form into a 'bootstrap modal dialog' which will submit data via ajax callback to callback function. The form display properly when the modal dialog is launched: <a data-toggle='...
arnaudom's user avatar
  • 119
6 votes
1 answer
2k views

From my child theme, how can I remove a library loaded by the parent theme?

I have hit an issue which I think is quite unusual or peculiar when settingup a child theme. A commercial parent theme I have bought loads the Slick library like this in its theme.libraries.yml: ...
Marcos Buarque's user avatar
5 votes
1 answer
2k 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 ...
Florian Müller's user avatar
5 votes
1 answer
3k views

Mark a location on a map (Google Maps/OpenLayers) on a node creation or edit page - but with which module?

I have a custom content type, and I would like my users to mark a location on a Google Maps/OpenLayers map, save these coordinates, and on the frontend, show the location's map and the GPS coordinates....
Sk8erPeter's user avatar
  • 1,799
5 votes
1 answer
4k views

Form states with "and" and "or" conditions

Using form API in D7, I need to use from states to setup a visible input with this condition : field1 = value A AND (field2 = value B OR value C OR value D) Something like this, but this example ...
Promo's user avatar
  • 365
5 votes
1 answer
198 views

Retrive $message variables in javascript file

I am using Drupal 7. In the template file page.tpl.php there is a variable called $message which prints the messages like error, warning etc. I want to access this variable in a JavaScript file. How ...
drupalninja's user avatar
5 votes
3 answers
10k views

How can I hide or show fields using states with hook form alter

We have been using Field States UI module with some success, but the Comparison Value does always not work for multiple values, I have tried to modify the valuse right in the entity_form_display.node ...
paul cappucci's user avatar
5 votes
2 answers
14k views

How to display a node in overlay popup effect?

I have a content type 'students' with fields name, description and a photo. I have created a view(Block) to display only the images of the students. When the teacher/user clicks the photo of the ...
Gladiator's user avatar
  • 650
5 votes
4 answers
5k views

Remove CDATA script from the page source

On my site i am getting some unnecessary CDATA script on the page source. <script type="text/javascript"> <!--//--><![CDATA[//><!-- jQuery.extend(Drupal.settings, {"basePath"...
user avatar
4 votes
1 answer
3k views

How to pass Javascript variable with form on submit?

I want to pass a variable created with Javascript to $form_state so that I can use this variable in the form_submit function. In an ajaxified form I can use: Drupal.ajax[ajax_el].options.data....
Daniel's user avatar
  • 149
4 votes
2 answers
7k views

How to minify Javascript in D7

I'm on rackspace's cloud sites service, so I can't modify my server environment. I'm also running Drupal 7. I've spent the last couple days looking for a way to minify JS in Drupal 7 and it is my ...
Bryan Casler's user avatar
4 votes
2 answers
1k views

Why doesn't my code for passing a PHP variable to JavaScript work?

I am using the following code, but the JavaScript console prints undefined instead of the value of settings.api_key. What is wrong in the code I am using? libraries.yml file stripe_files: version: ...
harshal's user avatar
  • 4,354
4 votes
0 answers
502 views

View exposed filter block no alter form with ajax

I am trying to filter out the no results items in my exposed filters. (I know i can use selective filters, but in this case i can't use them). So i alter the filters with form_alter, check which ...
mgoubert's user avatar
  • 377
4 votes
2 answers
5k views

How to add JavaScript or CSS library to Composer project?

For some cases, there is the need to add a JavaScript or CSS package to a project. One of those cases was the DropzoneJS package for the drupal/entity_browser. All recommendations I could read online ...
kaiser's user avatar
  • 301
4 votes
2 answers
4k views

How to trigger a form and pass variables to $form_state with jQuery?

What is the way to trigger a Drupal form via JavaScript, and pass new values to $form_state while doing so? I have a main form, which has an element that triggers a jQuery UI dialog with a form in it. ...
Danny_Joris's user avatar
4 votes
2 answers
3k views

What should I do to use a more recent jQuery version?

I am trying to use this jQuery Bubble script plugin with my Drupal 7 site. The plugin requires Jquery 1.6.2 (Drupal 7 only comes with 1.4.4). There are some solutions on the net but none seem to ...
big_smile's user avatar
  • 2,828
4 votes
1 answer
1k views

How to set cache meta data on drupalSettings?

I use drupalSettings to send config data to javascript. But when I edit my config, the javascript object is not modified, I have to clear all cache to get the update. The cache metadata in http ...
Teenage's user avatar
  • 362
4 votes
3 answers
3k views

How can I disable jquery_update when my admin theme is in use?

I have installed jQuery Update but it breaks some core functionality that makes the admin UI a struggle to deal with. Is there a way to keep jQuery Update enabled but disable it when the admin theme ...
markdorison's user avatar
  • 5,614
4 votes
1 answer
243 views

Why and what wrapper should I use for my module's JavaScript file?

I am defining a d3.js script for my module like this: test: js: js/test.js: {} dependencies: - mymodule/d3 - core/drupalSettings d3: remote: https://d3js.org version: "4.x" ...
dbj44's user avatar
  • 4,764
4 votes
1 answer
12k views

How do I create a form in a modal dialog with Drupal 7?

There seems to be many solutions for implementing a modal dialog including Ctools, Colorbox, Simple dialog, and Ctools Auto-modal. I'm not sure which is the best to use for simple coding through the ...
Adam S's user avatar
  • 5,031
4 votes
1 answer
2k views

Load and interact with a node comments from their related node

I am having some trouble in my quest to build a Drupal 7 custom node based image gallery module. I've got it working, but now I need AJAX to load and manipulate comments. What I am doing I've created ...
Macronomicus's user avatar
3 votes
2 answers
2k views

Adding jQuery UI selectmenu() to Drupal form

I'm trying to add a styling to the select form elements in my Drupal form using jQuery UI. I'm using Drupal 7 so the usual way to add jQuery UI would be something like this: drupal_add_library('...
KerrM's user avatar
  • 143
3 votes
1 answer
451 views

Ajax submission not working for Webform within a node

I am working with a feature where a newsletter subscription form (Webform with ajax submission and confirmation type is inline) should appear in a node. The node would be showing as a popup and the ...
Hemel's user avatar
  • 31
3 votes
2 answers
3k views

How do we use drupal_add_library(), drupal_add_css() and drupal_add_js()?

How do I use drupal_add_library(), drupal_add_css() and drupal_add_js() in Drupal 8? I am porting a module that uses those functions. I am following what reported in this post, which says these ...
Nitesh Sethia's user avatar
3 votes
1 answer
2k views

What are the available image sliders?

I want to know what sliders are available for Drupal 7, and which ones can be used in blocks.
EKK's user avatar
  • 4,350
3 votes
3 answers
1k views

Views UI doesn't provide links to expand fieldsets anymore

I have moved an entire drupal site to another server. While everything else seems to work fine, I can't quite access collapsed fieldsets in Views UI anymore. It looks like this All fieldsets (STYLE ...
Paul's user avatar
  • 1,213
3 votes
1 answer
3k views

Any way to alter script tag for some javascript and add custom attributes?

In order to work with Cloudflare's Rocket Loader service, certain scripts need to have their script tags updated with the cf-async="false" attribute like so: <script type="text/javascript" cf-...
Jordan Magnuson's user avatar
3 votes
2 answers
5k views

Different image for markers and cluster markers Openlayers

I want to display different markers for different event types eg. skiing (little guy on skis), sailing (little boat). I am using views so this shouldn't be hard. The fun starts when clustering. I ...
mediaashley's user avatar
  • 1,104
3 votes
1 answer
148 views

Integration between js and php code in custom module

I'm writing a custom module which outputs blocks with various deltas. Later, a jQuery code has to be attached for every generated block, aware of their id's, as in $('#mymodule-block-delta'). How is ...
no more drupal's user avatar
3 votes
2 answers
8k views

How to enable bootstrap tooltip and popover (on a bootstrap based theme)?

I'm using a theme based on Bootstrap 3. I want to use Tooltip and Popover features that come with Bootstrap but I couldn't. It's said on the Bootstrap Javascript page that: Opt-in functionality ...
herci's user avatar
  • 2,160
3 votes
1 answer
7k views

Best way for including javascript/jQuery OnLoad in EVERY page on my site

Currently, in my theme.info file I am including 2 scripts: scripts[] = js/backstretch.js scripts[] = js/scripts.js Backstretch is a jQuery plugin that allows for an expanding background image to ...
Matt Rowles's user avatar
3 votes
2 answers
8k views

Create an image slideshow with multiple image fields per node

I'd like to create an image slideshow using views slideshow. I see a few ways of doing it, like this one create-an-easy-jquery-slideshow-in-drupal-7, but they all require a single image per node. I ...
winchendonsprings's user avatar
3 votes
1 answer
1k views

Change user profile image on profile page to activate colorbox

This is for Drupal 7. Currently on the default user profile page, the profile picture just links back to their profile. I'd like to change this so it opens a colorbox. Thoughts? SOLUTION Add the ...
Lester Peabody's user avatar
3 votes
2 answers
183 views

Adding a jQuery interaction with Views Accordion [closed]

I have a Views Accordion displaying some books under their categories. I want to add some jQuery interaction, so when the user clicks the triangle of each category, the content will be loaded via ...
Cesar's user avatar
  • 932
3 votes
0 answers
130 views

Hide grey leaflet map if empty

I have a content type where the user gives a location, this is not a mandatory field. When the user don't provide location the node shows a grey map. Is there a way to remove the grey map from showing ...
Mat_Lab's user avatar
  • 51
3 votes
2 answers
1k views

How to create an Orbit slide show based on the zurb foundation?

I stubbornly tried to create an Orbit slide show based on zurb foundation 6 framework. I followed all the steps on the instruction page:Orbit Slide Show. I added everything needed for this type of ...
Mojtaba Reyhani's user avatar
3 votes
0 answers
271 views

In tabledrag form, how to prevent certain elements from having children?

I want to use tabledrag to manage 2 kinds of elements. Let's call them branches and leaves. Branch can be parent to both branches and leaves. Leaf cannot be parent to anything. A support for class ...
Mołot's user avatar
  • 21.9k
3 votes
1 answer
4k views

When using hook_form_alter to modify a content type's node add / edit form, where do I put the #states property?

This is actually a compound question. All in all the question is: When using hook_form_alter to modify an existing content type's node add / edit form, where do I put the #states property, and, ...
blue928's user avatar
  • 3,804