Questions tagged [ajax]
Use it for questions about JavaScript/PHP code to create asynchronous web applications.
2,530
questions
0
votes
1
answer
112
views
Why is my message not showing for anonymous user?
In a custom form, I have this Ajax submit:
public function ajaxSubmit(array &$form, FormStateInterface $form_state) {
$response = new AjaxResponse();
if ($form_state->hasAnyErrors()) ...
0
votes
0
answers
76
views
Why is CloudFlare blocking file uploads?
I have a simple form where people raise IT helpdesk requests (oh, the irony...) and this creates a case in CiviCRM. It's an unsophisticted but cheap helpdesk system for the few requests we get.
A ...
0
votes
1
answer
54
views
Why doesn't my completion message show?
I have this form to handle a custom content entity:
created by this code:
public function buildForm(array $form, FormStateInterface $form_state, $contractId = NULL) {
Some code to inialize ...
0
votes
0
answers
51
views
TriggeringElement not working properly for my ajax form
<?php
namespace Drupal\demo\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Component\Serialization\Json;
use Drupal\node\Entity\Node;
use \Drupal\...
0
votes
1
answer
97
views
Why does Ajax prevents managed_file to be displayed?
I have this form
created by this code:
public function buildForm(array $form, FormStateInterface $form_state, $contractId = NULL) {
some initialisation code...
$database = \Drupal::database(...
1
vote
1
answer
77
views
Can't access data posted from Dialog.ajax to dialog box
I am opening a simple dialog box from Ajax, using the following code-
var exportActionDialog = Dialog.ajax({
dialog: dialogSettings,
dialogType: 'modal',
type: 'POST',
url: '/web/admin/crm/...
0
votes
1
answer
76
views
How do i fetch the data from ajax callback by clicking on checkbox and show it in the checkbox?
I have to create a drupal10 custom form ->
In this i have created a checkbox with all the content types and when i click on any of the content type the ajax callback occurs which fetch the ...
-2
votes
2
answers
113
views
Revolution slider issue with AjaxResponse
I have an issue after drupal update to version 10 with Revolution Slider. This is an error I get:
Exception Error: "Call to undefined method Drupal\\\\Core\\\\Ajax\\\\AjaxResponse::create()" ...
0
votes
0
answers
53
views
Expired session - Invalid form POST data - Ajax
On my Drupal 7 I have a multisep form that uses ajax to validate and to submit the answer.
The form is used for an authenticated or anonymous user to answer a set of questions.
Everything is fine, ...
0
votes
1
answer
97
views
Loading webform in modal is too slow
I have webform with near 130 fields (text, entity checkboxes, radios, composite, etc)
Use it in modal:
<a href="/my-form?title={{node.id}}" class="webform-dialog" data-dialog-...
0
votes
0
answers
50
views
Node save button can be clicked while there is still running javascript which leads to unexpected behavior
We have Group module installed and a custom field.
To be more specific, we can set a value of this field from a dropdown list depending on the selected group.
The behavior is as follows:
Open content ...
2
votes
2
answers
65
views
How to access validated values after AJAX callback when fields are nested in a container?
I have a custom form where I have a search field and button. After the users clicks the button, I load some items based on what they've entered into the search field.
The problem that I'm having is ...
0
votes
0
answers
104
views
Set form values based on ajax callback
I am creating a complexed multistep form based on data from an Excel document. The user can save parts of the form using AJAX save buttons and updated data from the Excel document are displayed in the ...
0
votes
0
answers
28
views
How can I get conditional logic working when embedding a webform?
When embedding a multi-page webform within a render array using #type => 'webform', it seems like there's a bug where the conditional logic of webform elements does not work.
Note: The webform's ...
0
votes
0
answers
70
views
Ajax callback not returning options for checkboxes
I'm triggering an ajax callback on change event of a dropdown, this method returns additional form elements like text fields, number and checkboxes, but for checkboxes the options are not appearing at ...
0
votes
1
answer
32
views
File Field client side validation not working
I am on Drupal 9.3.x
I just discovered that File Field in node entity form which is marked as required, not showing client side validation fail message. Rather it submitting the form and then showing ...
0
votes
0
answers
302
views
Uncaught TypeError: Cannot read properties of undefined (reading 'messages') (forms AJAX POST)
Here I have created a custom module, which has one form in it...An ajax response is called when an Email is entered in form field and it will callback an HTML response.
I have tested this code on my ...
1
vote
0
answers
25
views
Allow access to Webform form URL only through Ajax
I'm using Webform to create some forms, those forms must be showed in modal through Ajax, and all of this is working good.
The issue is that I need URL to the form in order to load the form in modal, ...
0
votes
1
answer
52
views
Showing parts of ajax-enabled forms in Dialog and using submit buttons in Dialog to change the form?
I'd like to achieve the following (d10):
In a form a list of custom drupal plugins will be displayed. Each of those plugins has a settings form array depending on its type that will be merged into the ...
0
votes
0
answers
114
views
Using StreamedResponse for AJAX?
I am looking for a way with a Form API form in Drupal to have an #ajax event on a form field. When submitted, this calls a remote API.
How can I stream the response out to the screen without the ...
0
votes
0
answers
38
views
Commerce 2 - switch variation ajax error
I'm building a commerce site, one problem that I have is that the variation switch that works with ajax is having problems on the production server.
I have analyzed the network tab of DevTools, the ...
0
votes
0
answers
21
views
When "Use AJAX" is set to Yes on a View with Better Exposed Filters, the old search results are not cleared
Using Drupal 8, when AJAX is enabled on an exposed filter old search results aren't removed. I don't see any console errors but it seems that 'Use AJAX' isn't clearing the div before loading the next ...
0
votes
0
answers
50
views
How to change markup of modal dialogs
A modal form is defined in openModalForm(), and the modal form is called by $form['open_modal'].
public function openModalForm() {
$response = new AjaxResponse();
// Get the modal form using the ...
0
votes
1
answer
87
views
Error when trying to retrieve a term with ajax
We are creating a custom form to edit a certain node.
We do this above because there are some things that cannot be accomplished with the default form.
I want to use AJAX to populate the fields of the ...
0
votes
0
answers
564
views
How can I resolve the "Unique file URI" 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 this ...
0
votes
1
answer
248
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
30
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 ...
0
votes
1
answer
76
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 ...
0
votes
1
answer
145
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
773
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 ...
1
vote
1
answer
185
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
149
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
254
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
305
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
49
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
59
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
73
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
55
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
220
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
95
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
86
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
78
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
248
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
144
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
69
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 ...
2
votes
0
answers
317
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
242
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
200
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
63
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 ...