Questions tagged [ajax]
Use it for questions about JavaScript/PHP code to create asynchronous web applications.
2,513
questions
0
votes
0
answers
9
views
How to resolve "Unique file uri error" in Drupal 10 when using managed_file field in form API with a file name that already exists?
I am facing a strange issue with a managed_file field in my Drupal form API. Whenever I upload a file and save the form, and then come back again to upload another file with the same name, I get an ...
0
votes
1
answer
37
views
When a custom form is displayed in a custom template, ajax does not work
What I want to do
I want to display a custom form with a custom template and use ajax in it to change values in the form.
Problem
Custom template notation prevents ajax from working.
I didn't change ...
0
votes
0
answers
20
views
Report comments / Workflow
I am trying to implement a functionality that would allow authenticated users to report comments on a forum post. My first thought was to do it using workflows but comments dont have a workflow ...
-3
votes
0
answers
29
views
Why does opening modal break ajax on parent? [closed]
I am using the Draggable Views module to place a list of items on my page. Draggable Views allows me to drag the items around to change their order. There is then a Save Order button to ajax submit ...
0
votes
1
answer
26
views
trigger('RefreshView') problems with pagination
Colleagues, can you please advise: there is a views with enabled ajax and pagination, there is a form on the page (also ajax, but not views), which makes changes to the displayed views values. To ...
-3
votes
0
answers
28
views
Get AJAX button via AJAX
I've some controller, which returns Url::fromroute()->toString(), and it works in a template file, when I put it in <a class="use-ajax">. When I try to get it via AJAX, the link ...
0
votes
1
answer
34
views
Use AJAX On Node Add Form To Change Field Required Status
On a node/add form I have a pair of fields that need to be able to control one another. The first field allows a user to enter a birthdate, the second field allows the user to say the birthdate is ...
0
votes
1
answer
66
views
How to redirect custom ajax form to external url with headers
When setting the form with ajax handler like this
public function buildForm(array $form, FormStateInterface $form_state) {
//...
$form['actions']['submit'] = array(
//...
'#ajax'...
1
vote
0
answers
23
views
Focus Returns to Field With AJAX Callback [duplicate]
I am attempting to complete several AJAX commands based on the value of a field in a node/add form. The commands themselves work. However,when a user is filling out the form the cursor (focus) keeps ...
0
votes
1
answer
34
views
How do I debug A block ajax issue on a custom theme?
I'm receiving and ERROR " An error occurred while attempting to process /views/ajax?_wrapper_format=drupal_ajax: ajax.$form.ajaxSubmit is not a function" when clicking on link in views block ...
0
votes
1
answer
56
views
Add a text field value with AJAX
Problem:
After an AJAX callback, the text is not inserted in the body field.
Description:
I created a fresh Drupal installation.
Added a field 'Type' | field_type | List (text) to the Article CT.
The ...
0
votes
1
answer
81
views
Dynamicaly add ajax form item and add event on checkbox
I've added an ajax callback to my form to add some data on it :
$form['add'] = [
'#type' => 'button',
'#value' => t('add'),
'#ajax' => [
'callback' => [$this, '...
1
vote
1
answer
57
views
Problem with Adding new fields with Ajax call to a custom form
I have a simple form where I am trying to add a couple of fields to it when the user clicks a button using an ajax callback. Here is what I have:
public function buildForm($form, FormStateInterface $...
0
votes
0
answers
32
views
How to make an entity reference field only load a rendered entity, when clicking on it? (ajax load on click)
I want to mimic a zettelkasten system, by starting in a very simple way:
An entity of type 'Note' includes a body and an entity reference field, that can reference another note (of the same entity ...
1
vote
0
answers
52
views
Node edit form - Is it possible to load entity reference field data on click after the form has finished loading?
I have a custom node type (let's call it Project) with many fields. Three of these fields are of an Entity reference type, referencing other related nodes (let's call them Project Attachments A, B, ...
0
votes
0
answers
33
views
Ajax call brings all the Javascripts of drupal ruining the original page javascript
Based on this solution https://www.drupal.org/docs/7/api/javascript-api/simple-drupal-ajax-load-with-jquery-and-delivery-callback
I'm brining with an ajax call, a multistep form. The ajax brought ...
0
votes
1
answer
41
views
Node form field validations on change with AJAX
I'd like to be able to trigger the validations for a field, including relevant entity constraints, on a change (or equivalent) event for the field using AJAX. But I cannot figure out how to make that ...
0
votes
0
answers
34
views
Cookie value causing a "Uncaught Error: Call to undefined function menu_get_object() " error
There are plenty of posts regarding this Drupal error, but my situation is quite odd indeed. Here's the background:
I was asked to investigate an ajax error popping up on a form which does an account ...
1
vote
1
answer
44
views
Why is ScrollTopCommand not working?
I have a node edit form which I submit via ajax and then opens a modal doing this:
$form['actions']['submit'] = array_merge($form['actions']['submit'], [
'#value' => t('Get quote'),
'#...
0
votes
0
answers
45
views
Why is Admin Toolbar preventing modal from opening?
I posted this a few weeks ago: Why doesn't form submit callback get called? and with @4k4's help was able to get my custom form opening a modal when the form was submitted (see answer posted there)...
0
votes
0
answers
41
views
Callback Not Firing On Change
I am somewhat new to Drupal development. Please bear with me on this.
I am trying to create a popup after a user enters a value in a date field on a node/add form. This is on a Drupal 9 site. To do ...
0
votes
2
answers
171
views
Why doesn't form submit callback get called?
I have a custom page (controller) which embeds a node form. I want to submit this form via ajax but also run another submit handler which opens a modal with some of the values from that form.
My ...
0
votes
0
answers
58
views
Trying to populate one form select with another using Ajax, getting ajax.$form.ajaxSubmit is not a function
Building a custom module in Drupal 9.4.5. I need to have the user to select a country from one form select, and that would populate a second (states/provinces) using a form AJAX callback.
It works ...
0
votes
1
answer
54
views
Impossible to use custom fields in twig linked to form
I have a form in which I have two date fields and a filter button. This form is included in a custom view in which I have a table that displays data from the database. The date fields are here to ...
0
votes
0
answers
77
views
Refresh a form with Ajax after closing a Dialog
So I have a custom form in which I display a list of entities.
Below that list, I added an “Add More” link which opens a Dialog.
When I close (or submit) the Dialog, I want the list of entities to be ...
0
votes
0
answers
116
views
Action of webform displayed in modal opened by OpenModalDialogCommand in AjaxResponse
I'm trying to open a webform in a modal by using OpenModalDialogCommand in an AjaxResponse like this.
in buildForm method, I'm specifying AJAX callback like this:
$form['actions']['submit'] = [
'#...
0
votes
1
answer
102
views
How to identify ajax request in the exposed form of the View?
I have a View, it is ajax View.
There are exposed filters (with checkboxes). When I select a checkbox
\Drupal::routeMatch()->getRouteName()
shows general route name:
views.ajax
I need to change ...
0
votes
1
answer
49
views
Ajax validation of file upload in Commerce Product with product attributes
I am building a shop with Drupal Commerce right now. I have a product that uses an Order item type, which supports a file upload. The same product also has some product attributes that load the ...
0
votes
1
answer
51
views
managed_file not initialised after form ajax
I'm having issues with a managed_form field not beeing initialised after it is introduced via a ajaxcallback in a custom checkout Pane:
/**
* Provides a custom message pane.
*
* @...
-1
votes
1
answer
239
views
How do I implement an AJAX callback?
Given is a Drupal 9 project.
How can I make use of Drupal functionality through an AJAX call?
web/modules/custom/mymodule/src/Appointment.php
namespace Drupal\mymodule;
class Appointment {
public ...
-1
votes
1
answer
75
views
How can I avoid fields being disabled on AJAX requests (attribute disabled) in Drupal?
I want to make an input not be disabled when I submit an ajax request.
I tried reversed variants in these answers, i.e. hanging an "AjaxStart" on the document.
$(document).ajaxStart(function(...
0
votes
0
answers
58
views
How to alter form after doBuildForm call during AJAX response
I'm altering a form defined by a contrib module. Recently, that module switched to AJAX and my form alter isn't applied during the AJAX response. I believe the problem is in the following code used by ...
0
votes
0
answers
17
views
Ajax issue in tab when embedding a view
trying to add two views in panel in drupal 7 in one views it is working fine ajax like comment on ajax and all works good , but while switching on different tab ajax is not working fine.
in recently-...
1
vote
1
answer
313
views
AjaxCommand to scroll to top of page?
I have created an AJAX form. After the form is submitted, I call $this->createOkResponse() which updates a section of the page with a message (it replaces the form with the message).
It all works ...
3
votes
1
answer
589
views
How do I AjaxResponse on a custom AJAX call?
I have some custom Javascripts. at the part of code I want to leverage Drupal AjaxResponse but looks like it's only working when there Triggered by Drupal Form's ajax element. ( my ajax call verb is ...
0
votes
0
answers
110
views
Ajax MessageCommand is not using Bootstrap Barrio status-message theme template
I have a Controller in my custom Module which returns an Ajax Response:
$response = new AjaxResponse();
$response->addCommand(new MessageCommand('In den Warenkorb gelegt', NULL, ['type' => '...
0
votes
1
answer
121
views
Refresh ( or reopen) a Dialog (meida browser) with javascript
I have a media field, which when the user clicks on it, the media selector will open with the list of media.
I have a custom button there which do some ajax calls at the end I want to refresh the ...
0
votes
0
answers
151
views
Media Library and paragraphs not working
I have a paragraph with multiple fields, one of them is a media field (document type).
If I add a new paragraph and then add media I got "ajax error".
If I add new paragraph and save content ...
0
votes
1
answer
256
views
Drupal.Ajax.prototype.beforeSubmit results in AJAX Error
I have a module that creates an AJAX Form.
I need to copy some values from the DOM to a form field when (or before) the form is submitted.
In my module JS, I tried this:
(function($, Drupal) {
...
0
votes
0
answers
36
views
Using AJAX to Trigger an Event Based on the Value of a Date Feidl
I have a node type in Drupal 9.4 with lots of fields. The node type has some very simple form alaters to add additional instructions to the node add form. I also add a JavaScript file that shows users ...
0
votes
0
answers
102
views
Drupal.ajax() vs JQuery/$.ajax() – what is difference?
Official manual says
This scenario doesn't seems allow behaviours (to be confirmed)
Does it mean that Drupal.ajax()
shouldn't be called inside Drupal.behaviors.my_func
and/or inside JQuery's $.ajax?
...
0
votes
0
answers
88
views
Replace a Custom Block Via Ajax
I have a block on my page that shows summary information for a content entity. In particular, it shows a boolean value on if the user has watched a video or not.
I have already implemented that the ...
0
votes
0
answers
160
views
Ajax response to wait and retry
Use case
I am building a button to generate a pdf. The generation process can take a while.
Clicking the button triggers an ajax request which can meet one of 3 scenarios:
The pdf was already ...
0
votes
1
answer
55
views
Multistep Ajax form with ManagedFile: current step array dissapears from $form upon file upload callback
I have a custom multi-step Ajax form. On the second step, I have defined a managed_file field where users can upload several attachments:
public function buildForm(array $form, FormStateInterface $...
0
votes
2
answers
38
views
use-ajax class doesn't trigger ajax event
This is part of my code in custom module in src/Plugin/Block/FavoriteBlock.php:
$build['ajax_link'] = [
'#type' => 'link',
'#title' => $this->npxFavoritesRepository->getTitle($node),
...
0
votes
1
answer
49
views
Add an event listener to select list
I've attached the following js to an exposed views form field and it works on first page load but when the form is changed (by ajax) it doesn't fire.
I can't quite work out where to add an event ...
0
votes
1
answer
88
views
Multiple ajax form not working on whole site
I have multiple pages which contains multiple ajax forms. When I am working on a particular form, its ajax submission is working. But at that moment, if I go to second page form, ajax submission not ...
0
votes
0
answers
57
views
I lose template suggestions when an ajax event is called
I'm generating theme suggestions based on the formdazzle module, I made my own variant because I needed another level of granularity of theme names and it works fine.
Well, in the alter hook I have ...
1
vote
1
answer
224
views
AJAX in a plugin form results in "The specified #ajax callback is empty or not callable."
I have a configuration form for a Condition plugin I want to have ajax in. When selecting from this field, I want to get a list of displays for that View:
public function buildConfigurationForm(...
0
votes
1
answer
456
views
How to refresh and reload (with ajax?) order checkout panes and order calculation independent from commerce cart refresh (e.g. billing address change)
I have following problem:
During checkout, my customer has to fill in his billing address (at least at the first time) to calculate VAT rate and gross price. Further calculation is done via an order ...