Questions tagged [ajax]

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

Filter by
Sorted by
Tagged with
29
votes
5answers
57k 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 ...
15
votes
3answers
22k 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 ...
8
votes
2answers
6k 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 ...
8
votes
3answers
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' =&...
54
votes
3answers
19k 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' =&...
4
votes
1answer
9k views

How to load and display a view with Ajax in Drupal 7?

This is the first time I've ever tried to load a view using Ajax in Drupal7 and I would be appreciated if you help me from scratch. I've spent hours to learn how to do this but I still failed! I ...
2
votes
2answers
11k views

AJAX callback on form item generated by AJAX

I'm trying to add AJAX callback to form element that was previously rendered by AJAX but with no luck. Code below. A bit of description. There are three main methods here: buildForm - base form ...
1
vote
1answer
215 views

How to set the values of some fields depending on the value of a list box?

Remember the create password page of Drupal! while you are entering characters it tells you how string is your password! now I want to have something like this in a list box but a bit different. I ...
28
votes
7answers
51k 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 ...
4
votes
2answers
2k views

How to create (& pre-populate) multiple “field collection” fields on an ajax call

This is an extension of this question - "How to pre-populate multiple "field collection" fields in node form" I'm trying to do the same thing, but I'm trying to get it to work on an ajax ...
3
votes
2answers
5k views

How to trigger Ajax forms machinery

I'm working on ajaxifying a form which uses Hierarchical Select widget. I need to update a text field based on the value of HS and a couple of other fields. I want to use Drupal forms Ajax API. I ...
5
votes
2answers
8k views

How to omit form's validation at AJAX button click?

I have an AJAX button that should update form fields according to data already provided by user: 'ajax_button' => array( '#type' => 'button', '#value' => t("Scan for tags"), '#...
3
votes
2answers
6k views

How to override Drupal.ajax.prototype.beforeSend?

I need to add my own little if's and checks in 3 functions inside misc/ajax.js ( Drupal.ajax.prototype.beforeSend, Drupal.ajax.prototype.success, Drupal.ajax.prototype.error ) How can I ...
13
votes
2answers
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 ...
3
votes
2answers
4k views

Ajax submission leads to => An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (2 MB) that this server supports

So i'm trying to submit a form using ajax, in my form i have the following: $form['actions']['#type'] = 'actions'; $form['actions']['submit'] = array( '#type' => 'submit', ...
3
votes
1answer
782 views

Open ajax dialog with JavaScript

By adding use-ajax to a link we can open a modal using the Drupal ajax library as per the docs. E.g. <a class="use-ajax" data-dialog-options="{&quot;width&quot;:400}&...
3
votes
1answer
6k views

How do I submit a form via AJAX?

I'm using the Webform module for Drupal 8. The module confirmation settings for a form are the following: Page (redirects to new page and displays the confirmation message) Inline (reloads the ...
12
votes
1answer
9k 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 ...
8
votes
5answers
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 ...
7
votes
7answers
19k 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 :...
3
votes
1answer
8k views

AJAX dependent select

I know this has been asked before and I'm trying to use the example at Dynamic select list in the form (dependent dropdown) but I am struggling to get the desired results. The goal: Have a form that ...
7
votes
1answer
2k views

Override entityreference autocomplete and return entityfieldquery output

I am trying to override an entityreference autocomplete form item, I have managed to override the form, and get the arg passed to a hook_menu callback. However, I'm struggling with getting the ...
6
votes
2answers
6k views

How to extend or "hook" Drupal Form AJAX?

I'm working with standard admin form, which has 'add_more' button for one of fields. My task is to move some fields to jQuery UI Dialog just for usability. When dialog was closed I manually append it'...
4
votes
2answers
731 views

Changing the text displayed in an Entity Reference Autocomplete

I have an entity reference autocomplete which is populated using an Entity Reference View. I would like users to be able to type in this autocomplete and for the suggestions to look like this: "[...
3
votes
2answers
3k views

Changing file name on upload

I'm trying to automatically add prefixes to uploaded file names so they can later be processed by non-drupal scripts. I want to do that while the user is uploading files during creation/editing of a ...
2
votes
1answer
4k views

jquery script on view not working when filtering with (ajax on) 'better_exposed_filters' module

i have a script for dealing with node images hover (function ($) { $(function(){ $('.node-photos-teaser').mouseenter(function() { $(this).addClass('photos-hover'); }).mouseleave(...
0
votes
1answer
2k views

Remove tabledrag statuses on Ajax submit and display status message after Ajax submit

I've added drupal_add_tabledrag() on one of my custom forms, it enables the users to drag to reorder the elements' weights, which then gets submitted via ajax to a callback function that saves the ...
4
votes
3answers
7k views

drupal_add_js within AJAX callback

How can i add some data to drupal setting object using drupal_add_js withing some ajax callback? For example I have ajaxified flag link on my page, and have implemented hook_flag in my module, how ...
3
votes
1answer
2k views

Attach or embed node add form to a view

I want to attach or embed a node form to a view so that when a user submits the form, the view below the form will be updated in realtime via ajax. The form will be shown above the view. My views ...
2
votes
2answers
1k views

drupal 7 + services 3 - inserting nodes with select fields

I'm using Drupal 7 + Services 3 to create nodes with POST and JSON. Everything works fine, except field types of select - entity reference select or plain text. The entity reference uses the ...
0
votes
4answers
2k views

I get image field upload errors with a custom node_add() form

I've exposed a node_add form and styled it for certain roles to use. The form is being displayed in panels, through an 'article' node type using the PHP text filter. Users can create new nodes with no ...
34
votes
4answers
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 ...
21
votes
5answers
13k 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?
5
votes
1answer
8k views

Ajax reload of block on an event

I have created a block through custom module. The content of the block should be random every time it loads the block. Call back function for this was written. The block also has a link say "Next" and ...
13
votes
7answers
12k 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 ...
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 ...
8
votes
3answers
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?
14
votes
6answers
62k 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. ...
9
votes
1answer
3k 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 ...
9
votes
3answers
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'), // '#...
5
votes
1answer
12k views

Drupal 7 - How to get AJAX response displayed in a ctools modal?

I want to create a ctools modal popup when a button is pressed. function custom_form( $form, &form_state ) { $form['btn'] = array( '#type' => 'button', '#value' => t('add'), '#...
2
votes
1answer
2k views

Autocomplete textfield displays value when selected and not label

I have a textfield autocomplete field that shows a list of full user names and email addresses as designed but when a user is selected, the user id is displayed in the field; not the name and email ...
12
votes
6answers
4k 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 ...
9
votes
5answers
30k 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.
8
votes
4answers
9k 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 ...
2
votes
1answer
5k views

How can I add a progress bar to Managed File upload?

How can I add a progress bar to my Managed File form field? Here's my field code: $form['file'] = array( '#type' => 'managed_file', '#title' => t('Logo image'), '#description' => t(...
2
votes
2answers
2k views

Route AJAX failure messages to console instead of popup

How can I prevent ajax failure popups and instead route the failure to the console log instead? Is this something I can do with Drupals implementation of jQuery?
6
votes
1answer
1k views

Unlimited value field in custom form, with remove button

I'm working on creating an unlimited value field in a custom form, and getting hung up on the remove button. I've been able to create a form that will pull the saved values for the fieldset, then ...
5
votes
1answer
2k views

D7 form field #ajax callback not called on autocomplete field

I have an entity reference field, and I'd like to do some ajax so that when a value is selected for that field, some text is displayed in a div below the field. Since it's on a node edit form, I'm ...
4
votes
1answer
5k views

Creating module with autocomplete and accepting multiple values in textfield

I am creating my own form in my module using the Form API. How do I enter multiple values in the below textfield and have it autocompleted, and suggested (separated by commas, for example)? Right ...

1
2 3 4 5 6