Questions tagged [ajax]

Use it for questions about JavaScript/PHP code to create asynchronous web applications.

Filter by
Sorted by
Tagged with
55 votes
3 answers
20k views

Is it possible to replace more than one form element (wrappers) triggered by only one #ajax trigger element?

function ajax_example_simplest($form, &$form_state) { //This is my ajax trigger element $form['element_trigger'] = array( '#type' => 'select', '#options' => array( 'one' =&...
Francisco Luz's user avatar
35 votes
4 answers
18k 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 ...
Clive's user avatar
  • 167k
30 votes
5 answers
58k views

Dynamic select list in the form (dependent dropdown)

I'm using Drupal seven. I want to make the options in a select list be dependent on the value chosen in another select list in a form. I'm sure this has been asked many times before, but I am having ...
Ben's user avatar
  • 1,010
29 votes
7 answers
54k 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 ...
Daniel's user avatar
  • 1,245
21 votes
5 answers
16k views

How can I check if a request is an AJAX request?

I am looking for a Drupal way of detecting AJAX request. I need to check this inside hook_form_alter() when embedding views with AJAX support. How can I understand a request is an AJAX request?
Codium's user avatar
  • 4,955
17 votes
3 answers
5k views

What's the fastest method/implementation for an Ajax callback?

I have a map which loads markers via ajax on various/numerous map events. Currently, I define a custom page callback for my hook_menu() item which prints my json/js. Since my page callback does not ...
electblake's user avatar
  • 2,057
16 votes
3 answers
25k views

Load more content with ajax when clicking more link in a view

I have a custom block view. I display the last 5 node titles. If someone clicks the more link I want to load the next 5 titles underneath the current 5 node titles. No page refresh and not pager. Is ...
Lucy's user avatar
  • 1,502
16 votes
2 answers
11k views

Change $form_state in AJAX callback

I am creating a form which uses the form API '#ajax' attribute, and I need to make changes to $form_state when the AJAX-enabled button is pressed. Here's what I've got: Inside my form builder ...
MW.'s user avatar
  • 311
15 votes
3 answers
26k views

How can I implement AJAX form submission?

My task is to submit a contact form via AJAX and then to show a "Thank you for submission!" message, loaded in place where the form was. So I need to ajaxify existing contact form. I found ...
Sergey Kravchenko's user avatar
14 votes
4 answers
29k views

How to load content in a div with ajax?

After validate with javascript that I'll be able to use the client location: if (navigator.geolocation) { ... I need to load the content of a view block with arguments (based in the position coords)....
Adrian Cid Almaguer's user avatar
14 votes
6 answers
63k views

How to validate and submit a form using AJAX?

I've created a webform using the Form API. I'm using the #AJAX field option to add AJAX validation to each field. Is it possible to validate and submit the form using AJAX without reloading the page. ...
Camsoft's user avatar
  • 3,139
13 votes
3 answers
35k 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 ...
Paul Sheldrake's user avatar
13 votes
6 answers
5k views

How to display more than 10 items in link widget autocomplete?

This is a question about the Link module. Since with the Link module you can enter external or internal links both, we strongly rely on it. Unfortunately the number of items to be displayed from its ...
leymannx's user avatar
  • 18k
13 votes
7 answers
13k views

Status messages with AJAX

I'm making an AJAX call in drupal 7 via the standard AJAX Framework. My problem is that when a status message is set by the AJAX callback, it is simply lost (or displayed at the next reload of the ...
mimrock's user avatar
  • 357
13 votes
1 answer
391 views

Webform-CiviCRM integration: autocomplete employer

I set up a Webform for a Membership Application. I followed the instructions on this page for setting up an Autocomplete for the Organization the new Member belongs to: http://wiki.civicrm.org/...
Christopher Dunning's user avatar
13 votes
2 answers
4k views

How to Disable new terms (free tagging) with Taxonomies?

I have a "term reference" field, in a form that uses an auto-complete widget. I want to limit user input to terms in the vocabulary only, and output a message when a user tries to enter a non existing ...
user1774549's user avatar
12 votes
1 answer
12k 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 ...
user70961's user avatar
  • 145
12 votes
3 answers
17k 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 ...
JSL's user avatar
  • 141
12 votes
2 answers
17k views

How to rebuild form after AJAX call

I'm attempting to allow the user to dynamically choose a number of fields based on a dropdown box using an ajax call, but I can't seem to get the ajax call to rebuild the form afterwards. <?php ...
Amy's user avatar
  • 5,662
12 votes
2 answers
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 ...
PartySoft's user avatar
  • 1,036
11 votes
2 answers
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 ...
dennis605's user avatar
  • 483
10 votes
5 answers
27k views

How to avoid "An illegal choice has been detected" when updating select list values via ajax?

I have four entity reference fields to user entity in a form. Host form is node edit form. Three of them are select lists, last is Inline Entity Form. After adding a user entity via IEF I'm trying ...
Codium's user avatar
  • 4,955
10 votes
8 answers
25k 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'...
Mike Crittenden's user avatar
10 votes
3 answers
8k views

Manually invoking Ajax Commands when an ajax callback is not an #ajax form callback

My original post caused some confusion, so I'm re-writing it for clarity. In Drupal, if you have an #ajax callback in a form, you can do something like this: function my_ajax_callback(array &$...
Jaypan's user avatar
  • 17.4k
10 votes
2 answers
3k views

Views exposed filter auto submit loses focus

I have setup a view with ajax enabled. I have also added an exposed filter with autosubmit on so that as the user types in the text field the view will automatically update. The problem is that when ...
MWay's user avatar
  • 273
10 votes
1 answer
937 views

Add line item showing total cost

How can I add a line item in Ubercart 2 that adds up the total cost of all items, not the sell price? I have tried to clone the generic line item hook, and add something like this for the callback: ...
user2591's user avatar
  • 101
9 votes
5 answers
9k views

Debugging #AJAX and FormAPI

What is the easiest way to view current $form_state variables while working with #ajax? Is there a way I can get dpm() to update automatically on each AJAX load? If it matters, I'm testing AJAX on a ...
Citricguy's user avatar
  • 7,924
9 votes
2 answers
11k views

How to do a hard redirect when in Ajaxified form?

I have an Ajax multistep form and I want to redirect user to specific route when some conditions are met (specifically if the user is inactive for more than N seconds and the form is submitted after ...
user avatar
9 votes
5 answers
32k 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.
sel_space's user avatar
  • 1,134
9 votes
2 answers
8k views

Invoke custom JS function in AJAX callback?

Is it possible to invoke a custom JS function in an AJAX callback? function MY_MODULE_ajax_callback() { // Define a new array to hold our AJAX commands. $ajax_commands = array(); // Create a ...
Alex Gill's user avatar
  • 3,432
9 votes
2 answers
4k views

How to prevent an Ajax form from submitting

The below code blocks any non-ajax form from submitting. $(this.form) .on('submit', function(event) { if (/* Some condition */) { event.preventDefault(); } }); In Drupal 8, how can ...
jrockowitz's user avatar
  • 4,623
9 votes
5 answers
4k views

Why does #triggering_element pick the wrong element?

I'm triggering an ajax-enabled button on a form but Drupal's setting $form_state['#triggering_element'] to the wrong element. The button is a child of a #tree and is identical to other buttons in ...
artfulrobot's user avatar
  • 4,009
9 votes
5 answers
8k views

Delay ajax call on textfield to allow for typing

I would like to delay ajax from firing in the same way that the autocomplete seems to work. For example, if a user it typing, the ajax will not run until 500ms has elapsed since the last keyup. I am ...
Inigo Montoya's user avatar
9 votes
3 answers
10k views

How do I create a progress bar?

I need to implement a progress bar using Drupal 7. This is the code I am actually using. $form[$name][$name.'_enc'] = array( '#type' => 'submit', '#value' => t($name.' Enable'), // '#...
amr's user avatar
  • 91
8 votes
3 answers
7k views

Show node IDs along with titles in Entity reference Autocomplete list

I'll like to add this functionality to the autocomplete widget in Entityreference field to show node ID next to the titles in the dropdown list. The reason behind the idea is to differentiate between ...
neemu's user avatar
  • 81
8 votes
5 answers
11k views

How do I add a "Add more" button?

I want to show a Add more button that adds an extra text field and the corresponding Remove button. I followed ajax_example_add_more() to achieve this in Drupal 7. For Drupal 8, I tried with the ...
Sugandh Khanna's user avatar
8 votes
3 answers
11k views

Disable all form elements when doing AJAX

I have a form where every user input field is AJAX enabled, and I'd like to disable all of the form elements when one of them is changed - is it possible?
Daniel's user avatar
  • 1,245
8 votes
5 answers
15k views

How to add extra arguments/parameters to ajax callback function?

I am using drupal 7. I need to add extra arguments to my ajax callback function. I have five fieldsets in my form, and in all of them same there are same elements, just their IDs are different. For ...
Bora Semiz's user avatar
8 votes
3 answers
10k views

Can I use ajax to target multiple form elements from one input?

I'm trying to use ajax to update two different parts of a drupal form from just one form input blur. I have the standard ajax stuff on my input: $my_form['my_input']['#ajax'] = array( 'callback' =&...
Rick's user avatar
  • 471
8 votes
3 answers
9k views

How to ajaxify webform submit in Drupal 7?

I have tried to alter the webform rendering using hook_form_alter() and hook_node_view() in a custom module so I could add '#ajax' somewhere. Has anybody already had some experience working with ...
E. de Saint Chamas's user avatar
8 votes
3 answers
5k views

How to add confirmation to ajax link?

I am rendering ajax link as follows: l(t('Click here'), 'mypath', array('attributes' => array('id' => 'my-id', 'class' => array('use-ajax')))); How to display confirmation dialog before ajax ...
tomas.teicher's user avatar
8 votes
1 answer
10k views

How to Use Ajax in form alter in Drupal 7?

I have created a content type named "main menu". I have few select lists which depend on one another. I wanted to display a different list when different checkboxes are selected. I figured out that I ...
Drupal Developer's user avatar
8 votes
1 answer
6k views

How to load a view with ajax so that additional js/css files needed by the view are also loaded?

Currently I'm using jQuery to load a view, like this: $.ajax({ type: 'POST', url: Drupal.settings.basePath + 'views/ajax', dataType: 'json', data: 'view_name=' + viewName + '&...
Temaruk's user avatar
  • 499
8 votes
2 answers
4k views

Slow "Add another item" with unlimited valued fields

In Drupal 7, when you have node with field which has unlimited values (let's say, image field), "add another item" response time becomes very slow after you added 10 - 20 items. How do you fight this ...
Timur Kamanin's user avatar
8 votes
2 answers
12k views

How to submit webform programmatically with Ajax?

I'm working on an Ajax implementation for the Webform submit on Drupal 7. I was not able to find any good hook to alter the Webform submit button and add '#ajax' in the form so i had a look to a ...
E. de Saint Chamas's user avatar
8 votes
6 answers
4k views

Why is this Drupal services RESTful API not working?

I'm using the Services module on Drupal 7. I want to implement a service that allows me to submit a search term via AJAX and receive an array containing the top 5 nodes (node id and title) that ...
rybosome's user avatar
  • 941
7 votes
3 answers
9k views

Clear form fields after AJAX submit

Given: I am using Drupal 8. I have a custom "add form" of the custom entity type. Form has an ajax submission. Problem: When I submit form all the values remain in fields. Expected: Form fields ...
milkovsky's user avatar
  • 5,334
7 votes
3 answers
9k views

Autocomplete textfield widget?

Does anybody know of a Drupal 7 autocomplete widget for textfields? I've tried Autocomplete Widgets, but the "Autocomplete for allowed values list" widget from that doesn't seem to exist in Drupal 7 --...
BenjaminRH's user avatar
7 votes
7 answers
21k views

How can I trigger a javascript function when a Drupal ajax call is complete?

I need to do some extra things after Drupal ajax is done inserting some stuff into the DOM. With jQuery this was brain-dead simple, but I can't for the life of me figure out how to do it in Drupal 7 :...
SomethingOn's user avatar
  • 1,281
7 votes
2 answers
749 views

What difference between declaration of an ajax callback function with $this and without it?

There is a form working with AJAX Framework. And there is a form element having the callback function named "myFunction", which is a public method of the form class. The callback can be declared as '...
Yakimkin Roman's user avatar

1
2 3 4 5
51