Questions tagged [javascript]

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

Filter by
Sorted by
Tagged with
53
votes
2answers
39k views

Better understanding of Drupal behaviors

I read about Drupal behaviors today, and I tried writing the following code. (function ($) { Drupal.behaviors.mymodule = { attach: function (context, settings) { $('#mymodule_id', ...
42
votes
3answers
47k views

how to send variable from .php file to .js file?

I hope someone is able to help me. The problem is the following one: 1)I have module in which a assign the variable in order to send to the template file php.tpl <?php ... $testvar="Hello from ...
34
votes
4answers
17k views

How do I change the ajax loading behaviour in Views?

I have a view with some exposed filters in a block; it uses AJAX and the auto-submit feature so the view is re-loaded as soon as a filter option is changed. In the short delay between selecting an ...
34
votes
4answers
44k views

How do I update jQuery to the latest version I can download?

I'm using Drupal 7, which uses jQuery 1.4 as default? How can I update it to the latest version (currently 1.7)?
30
votes
8answers
19k views

How to make a form required with states?

I have a drop down list that displays various fields based on what is chosen and I know that I can toogle the visibility with states but when I try to use required the * span is display but it isn't ...
30
votes
2answers
33k views

Eliminate render-blocking JavaScript and CSS in above-the-fold content

I am building a Drupal 7 site. These are some of the modules I use: Adaptivetheme (theme), Views and Content Panes, Panels, Mini panels, Panels everywhere, Page manager, Superfish for menus, Addthis, ...
29
votes
5answers
24k views

How do I add JavaScript specific for a view?

I have a view in my site that has a specific class name. I want to know, inside the template.php file of a theme, how I can know if a view with specific class name is available in the requested page. ...
27
votes
7answers
48k views

How to programmatically trigger a click on an AJAX enabled form submit button?

I'm trying to programmatically (with jQuery) trigger a click on button with AJAX behavior in a Drupal form, but so far jQuery('#edit-submit').click() doesn't do anything. A real mouse click on that ...
24
votes
6answers
21k views

Using built in jQuery UI in my theme

Every page of my theme will need to use jquery UI. I know it's included with Drupal 7, but I can't really decipher Drupal's way-too-technical documentation. It looks like the only way to do it is ...
22
votes
4answers
5k views

Using a framework like Backbone [closed]

I currently have a page http://proctors.org/tv that is driven by several views and attachments with tons of jQuery and hacked-together JavaScript spaghetti, and I would like to clean it up. I ...
20
votes
2answers
22k views

Add external javascripts

Is it possible to add external javascripts directly into the .info file of a theme? e.g scripts[] = http://cdn.jquerytools.org/1.2.6/jquery.tools.min.js
19
votes
3answers
11k views

Multiple Values to Trigger #states

How can I have multiple values trigger the Form API's #states? Say for example, I wanted this field to be visible not only if the value is 5 (currently works below), but wanted to make the field ...
19
votes
12answers
29k views

How to add Jquery plugin to Drupal?

Should I just paste the code in the main template file, or is there any other recommended way of attaching new Jquery plugins in Drupal 7?
19
votes
4answers
8k views

Easiest method for conditional fields in a form

What is the easiest way to get some javascript magic for enabling/disabling form fields based on another field's value? This sounds like something there should be an helper for somewhere, but I can't ...
17
votes
1answer
50k views

How to get rid of added URLs when printing a Bootstrap-themed page?

When I print a page from my Bootstrap-themed site, all the links (and images with attached urls) have a printed representation of the link inserted into the printed page, right after the linked object....
17
votes
5answers
14k views

Add JavaScript files to the administrative pages

How do I add JavaScript/CSS files in every administration pages, using a module?
17
votes
5answers
5k views

Including a different jQuery version only on specific page

jQuery update module is including this script. <script type="text/javascript" src="/sites/all/modules/jquery_update/replace/jquery.min.js?6"></script> I need this on every page, except a ...
17
votes
3answers
6k views

Drupal 7 & jQuery — the $ dollar sign

If I'm not planning on using any JS libraries other than jQuery, is there any reason to need Drupal's call to jQuery.noConflict() which removes $ as an alias for jQuery? Assuming there is no need for ...
17
votes
3answers
3k views

How to handle / cleanup obsolete aggregated css / js?

I'm only using Drupal 7 built in CSS / JS aggregation, however the files folder where the css.gz and js.gz files live are filling up at a fairly rapid pace, and while I'm sure it'll be a while before ...
15
votes
5answers
31k views

Add JavaScript at the bottom of a page

How can I add JavaScript scripts to bottom of a page, in my template?
14
votes
2answers
8k views

Changes in the way Drupal 7 handles JavaScript and jQuery

I'm currently developing a JavaScript script that runs on an administration page. I read up on the changes made in Drupal 7, namely the move from document.ready() to its own jQuery function. However, ...
13
votes
5answers
9k views

How to prevent behavior-attached functions from being attached twice?

I have a behavior that adds on to some checkboxes. (function($) { Drupal.behaviors.mymodule = { attach: function (context, settings) { $('.skip-line', context).on('change', function(){ ...
13
votes
2answers
17k views

How can I return actual JSON using Drupal?

I'd like to implement a simple AJAX function locally that allows me to autocomplete node titles of already existing nodes as the user types. To that end, I need the ability to have an API that I can ...
12
votes
3answers
30k views

Listen to AJAX complete event from a behavior

I have a form that has an AJAX button. When I click it, it updates a bunch of stuff as expected which is fine. I was wondering if there is a way to create a listener in behavior that gets called ...
12
votes
1answer
9k views

How do I use a jQuery version different from the default one used by core?

I need to use a different jQuery version. Currently, Drupal is using jQuery 3.2.1, but I need a previous version. In Drupal 7 you could easily change jQuery version with the jQuery Update module. How ...
12
votes
2answers
5k views

Drupal's attach behaviours : react on all newly loaded content?

I've got two different modules which in many ways work together. One of the things they work together on is that module A loads content via AJAX, and module B needs to attach event listeners to the ...
12
votes
2answers
10k views

load a node content into a lightbox2 (without headers and footer and other blocks)

is it possible to load a node (from an id) into a lightbox 2 without having to load all the additional blocks ? just what the node has to display I want to make some popups on some links to allow ...
11
votes
4answers
3k views

Using a newer JQuery version

The Drupal 6 version of jQuery is too old (1.26). Could I delete, and replace it with a newer version?
11
votes
1answer
6k views

How can I alter a module's JavaScript?

I need to alter the "Webform AJAX" module's JavaScript code. Is this possible without hacking the module, and risking losing it all upon module updates?
11
votes
2answers
7k views

How can I use jQuery 1.7 without having issues in the admin pages?

Is anybody successfully running jQuery 1.7? I'm using a jQuery component on my pages which requires jQuery 1.7 or later. This version causes some unwanted side effects in the admin UI, such as checked ...
11
votes
5answers
753 views

How to start views at %nid position (from path)?

I have a portfolio showing somes nodes (views3 + views slideshow using cycle). Everything works fine, I've a default path /portfolio to access to it. However, I'm trying to set a path for each slide. ...
10
votes
5answers
18k views

hook_preprocess_page(): how to tell a views page?

Im writing a custom module that need to insert some javascript and css files only in a Views page. Im using hook_preprocess_page, but I can not tell if the current page is from a view: function ...
10
votes
8answers
22k views

How to add a JS confirmation popup when clicking an #ajax button

I have a basic FAPI button input that is #ajax enabled and that's working fine, but I want to add a JS "Are you sure?" confirmation popup when clicking the button before the code actually runs, and I'...
10
votes
5answers
12k views

How to add conditional javascript to theme?

I'd like to use Selectivizr script to emulate CSS3 selectors in IE6-8. But I'm having a hard time adding it to my theme. So far tried: 1) Forcing this into html.tpl.php head section: <!--[if lt ...
10
votes
2answers
18k views

Force Drupal to attach Drupal behavior to new ajaxed content [only Drupal.attachBehaviors() is not working the right way]

I was doing lot of posts on drupal.org about this topic, but unfortunately in the wrong context. Ajaxed content is not attaching needed JS and CSS (forum) Ajaxed content is not attaching needed JS ...
10
votes
4answers
16k views

How to create modal windows (pop-ups)?

I am trying to use Drupal 8's core function to open a page in a modal window. Unfortunately it is very hard to find some official documentation about it, and most of the blogs covering this topic seem ...
10
votes
1answer
7k views

How to Trigger Existing, Non-Form Ajax from JavaScript Event

I'm trying to figure out AJAX in Drupal 8. I have a custom module that works, using AJAX to change the content of a div when a link is clicked. The API says: Many different events can trigger ...
10
votes
3answers
9k views

What is the best way to minify drupal's aggregated javascript (automatically)?

Have just run Google pagespeed over my newly created drupal 6 site, and it reports: Minifying the following JavaScript resources could reduce their size by 15.6KiB (12% reduction). Minifying ...
10
votes
3answers
15k views

How to trigger Drupal.attachBehaviors after successful Ajax

I have a module that updates a node via ajax when a link is clicked. The link is a toggle, it should update the node with value 1 on first click, then with value 0 on a subsequent click, etc. Like ...
9
votes
2answers
15k views

How do I include JavaScript on a single page in a way that is amenable to scale

I've read through a bunch of material about using JS in Drupal 8 theming and module development, but did not come away with an understanding of the most straightforward way to routinely add things ...
9
votes
2answers
19k views

How do I add JavaScript to a site?

How can I add JavaScript and CSS to my site?
9
votes
5answers
26k views

What's the event triggered after an autocomplete has run and how to retrieve the value selected

I have a node add form with a term reference that uses autocomplete widget. I want the "tid" of the filled term by the user using the autocomplete widget.
9
votes
3answers
11k views

How do I add CSS & JavaScript to <head>?

I want to add the following code in my section of the front page using a Drupal 8 sub theme of Bartik. Can anybody help how to do it? What is the best way to do it in this new twig version of theme?...
9
votes
4answers
19k views

How to make form buttons call only javascript?

I'm experimenting with JavaScript and Drupal forms. Currently I'm trying to make a button in the administration form of a module that will use JavaScript to append options to a select list. The ...
9
votes
4answers
9k views

Add JavaScript into a specific content type

I would like to know what is the best way to add a JavaScript file into a specific page basing on the content type. For example, I want to add this: <script type='text/javascript' src='http://maps....
9
votes
3answers
3k views

Hide a CCK fieldgroup using #states in hook_form_alter()?

I have a custom module, and I am trying to hide a CCK fieldgroup using "#states" when a certain item is selected in a drop-down select list. I have tried using states from within hook_form_alter(), ...
9
votes
3answers
7k views

How can I control the order of Drupal.behaviors?

I want the JavaScript code from module X to run only after the one from module Y has run. Whats the best way to do this?
9
votes
6answers
1k views

How to implement a Comment Reply Form through Views and using JS?

We have a comment body, using views, where we have the name, comment, picture, and date for each of the posted comments. At the end of all comments we have a comment body, where one can add a comment. ...
8
votes
4answers
10k views

How to get the node ID in jQuery/JavaScript

Is there a definitive, universal way to do this? For example using some environment variable that comes with Drupal.behaviours? I have done some research and there seems to be no common answer.
8
votes
2answers
12k views

How do I get a module path?

I'm creating a module in Drupal 8 and I need to define a relative path to mymodule to pass it on a JavaScript file like this. $scope.getPlatformIcon = function (_platform) { var modulePath = "/...

1
2 3 4 5
62