Questions tagged [ajax]

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

Filter by
Sorted by
Tagged with
1
vote
0answers
17 views

How to filter autocomplete on a dependent field?

Goal - How to filter autocomplete based on a related field? In this domain, an organisation is selected and then the autocomplete should only allow items created by that organisation to be selected. ...
0
votes
0answers
24 views

Load view form with ajax missing ajax functionality

When clicking an element I get a form which is generated by a view (using https://www.drupal.org/project/editablefields module). The problem is that the ajax functionality of the form is lost (no ajax-...
0
votes
0answers
21 views

Run php code on text field in variation possible?

Is it possible - anyone know how - to run php code on a commerce 2 variations created field to check the data in that field maybe using Ajax to make the field typingsensitive in the checkout?? I ...
0
votes
0answers
24 views

Update body field from ajax callback

I need to update the common "body" field when I change some paragraph fields value. Here is my hook_form_alter : $form["body"]["#prefix"] = "<div id='...
0
votes
0answers
25 views

Need help with AJAX calls within Drupal.behaviors

I'm having some issues getting the following code to work correctly: (function($) { 'use strict'; Drupal.behaviors.mybehavior = { attach: function(context, settings) { // Click on a ...
0
votes
1answer
36 views

Use ajax to save modal / dialog form instead of page reload

I'm looking for a way to save modal & dialog forms through ajax instead of redirecting the user after the form submit. Ajax is quite unknown territory to me. I've found several interesting topics ...
0
votes
0answers
17 views

Can I bind ajax to form or document?

I would like to bind an update to entity browser select. It is a standard ajax form response. Update the default value of another field. If I apply the ajax to the inline entity browser form field it ...
0
votes
0answers
22 views

Ajax message after node save

I am trying to add a Ajax Alert or popup message inside a hook_node_presave or hook_node_update, but it is not working. My current code look like this, but I have tried a lot of other ajax $response = ...
0
votes
0answers
28 views

Controlling dropdown field visibility using #states API for dependent dropdown

I have the following setup. dropdown_one [ '#type' => 'select', '#title' => $this->t('Dropdown one'), '#options' => $dropdownOneOptions, '#empty_option' => '---', '#...
0
votes
1answer
33 views

entity_form how to programmatically add references and update the form visually (entity_browser)

I´m having an fieldable entity with a reference field to paragraphs field_paragraphs and a paragraph_type with a reference field to content_type event field_events. What i am trying in the entity form ...
0
votes
0answers
26 views

Is there any way to add JS to form only when loaded using ajax-api in modal?

I have one page on which there is a button. On click of that button I am opening a webform in modal popup (Ajax dialog). What I need is to add a GA script to the form. I have tried using ...
0
votes
1answer
82 views

How to configure a custom POST api to accept a request with Content-Type as "application/x-www-form-urlencoded" in the header?

I created a controller in a custom module that accepts a POST request. I have a setup such that I get a POST request from a third-party application server to this API. But the POST request has a ...
-2
votes
1answer
46 views

How to open a form in modal from controller while redirect

I can open a form in modal when click on a link (and there are lot of examples in the net as well). What I like to do: When some one go to a url in browser or redirect to a url, it will open a dialog/...
-1
votes
2answers
37 views

How do I add ajax callback to a form element which is created in a foreach loop

Please see the following code: foreach ($formaddresses as $key => $val) { // Add edit buttons to custom client-side created addresses. if (!isset($val['accountnumber'])) { $form['orderinfo']...
0
votes
0answers
28 views

How to see if ajax has been added to a simple node form?

This very simple #ajax customisation to a node form is not working. How can I tell whether the callback has been added? I want to calculate a field if the first field is changed. function ...
0
votes
1answer
30 views

How disable submit button after call OpenModalDialogCommand in Ajax callback?

I have a block that has a button, when pressing that button an ajax is triggered that shows a popup with the OpenModalDialogCommand event, after closing the popup I want to deactivate the submit ...
0
votes
0answers
50 views

Ajax form ReplaceCommand functionality breaks after first fire

I Have a form on a page which updates a single field of a Node. The form uses ajax to update the field and returns the newly saved entity and replaces the current HTML so the new field is showing up ...
1
vote
0answers
27 views

Refresh view using ajax with parameters

I use this code to refresh a view, but It reloads the view ignoring neither page number nor filters. $('.view-id-name').trigger('RefreshView'); How could I pass parameters (page number, query filters,...
1
vote
0answers
39 views

AJAX callback is fired only once

I am using hook_form_alter() hook to add an Apply button to the node edit form.. When users click on that button, an AJAX callback replaces the text field value. It works fine the first time, but the ...
-1
votes
1answer
31 views

drupal custom callback in node edit form is not firing

i am fairly new to drupal , i have custom button added to one the content type edit page , when i click on that button i want to call a function but it seems like it is not calling function when i ...
1
vote
0answers
35 views

Send an AJAX response and rebuild a form in a single AJAX callback

I need to execute multiple AJAXCommands and rebuild form in one AJAXCallback function, but the documentation says the AJAXCallback function should return AjaxResponse OR FormElement. Using ...
2
votes
1answer
42 views

Custom Submit Callback only triggering when Form is Valid when in Dialog

I'm trying to create a node in a dialog with the following link: Enter the title of a registration form or <a class="use-ajax" data-dialog-options="{&quot;width&quot;:...
0
votes
0answers
51 views

How to close a modal with a submit form and implement a CloseModalDialogCommand?

I saw this issue here, but I wanted to post this question as the answers seem incomplete and the question is not specific to closing a modal with a submit form. In my .module file, I am using a ...
0
votes
0answers
15 views

Admin custom configuration form add more field issue

I have created below admin custom configuration form by taking a reference of below examples: https://git.drupalcode.org/project/examples/-/blob/8.x-1.x/form_api_example/src/Form/AjaxAddMore.php How ...
0
votes
0answers
24 views

Form API States required don't seem to work on a custom form with ajax [duplicate]

I can't get form states required to work on an ajax submitted form. Here is some example code. It is taken from the examples module and slightly modified to illustrate the problem. /** * {@...
0
votes
1answer
17 views

Add rows to form tableselect with AJAX

I would like to: 1.) Add rows to a tableselect form element when a user clicks on a button. 2.) See which rows are selected when a user clicks on another button. Part one is complete (I've only ...
1
vote
1answer
76 views

Ajax form inside custom system.404 route controller doesn't work

I need to display custom logic in 404 pages so I have overridden the route controller of the system.404 route like this: class RouteSubscriber extends RouteSubscriberBase { protected function ...
0
votes
1answer
17 views

Checkbox Ajax call back giving me error

New to drupal 7, following code should work fine according to my knowledge can someone help me why ajax give me error in console ? and what the solution Code function ...
0
votes
1answer
56 views

How to add a secondary Ajax submit to a regular node form?

I'm trying to add an Ajax submit to a regular node edit form (Drupal 9). I'm using Field Groups so that there's a series of tabs, and I've added a pair of "buttons" (Right now they're just ...
-1
votes
1answer
35 views

Why do I get "An invalid selection has been identified." from the form my code creates?

I am using the following code for a form. public function buildForm(array $form, FormStateInterface $form_state) { $region_options = static::getFirstDropdownOptions(); $form['vvv_region'] = [ '...
-1
votes
1answer
51 views

Jquery to move field above the table - changes during page refresh

I have the below jquery code to move a multiselect field and a button above the table. jQuery(document).ready(function($){ $('#views-form-resources-block-1 .form-item-ka-types').insertBefore($('#...
0
votes
0answers
33 views

How to save a ajaxified value in a form

I add a ajax callback to a select field $form['field_equipe_membre']['widget']['#ajax'] = array( 'callback' => 'ajax_desactive_unites_field_callback', 'event' => 'change', 'method' => 'html', ...
1
vote
1answer
104 views

buildForm: how differentiate between page reload and ajax callback?

I'm building a custom form in Drupal 9, which has some ajax callbacks. During the buildForm I need to load some extra data via a rest call to an external service, which then I put inside a ...
0
votes
0answers
44 views

Form with ajax and javascript problem

I re-create the question with more accurate data (Original question Form with ajax and javascript problem). I have a button in my form that generates a fieldset via ajax. When I try to track this ...
1
vote
1answer
86 views

Somehow subscribe/react to addMessage

I'm trying to find an event that I can subscribe to for the method addMessage. I need to trigger some code everytime a status message is added. On reacting to this event, I need to send a variable ...
0
votes
0answers
24 views

save a selection from an ajaxified field

I successfully update a field from ajax. Its declaration is the following : $form['field_unite_de_recherche']['widget']['#ajax'] = array( 'callback' => 'ajax_equipes_from_unites_callback', '...
0
votes
0answers
25 views

rebuild a form with ajax (solved)

In a hook, I use ajax on a form field, designed with drupal user interface. It is declared as this : $form['field_unite_de_recherche']['widget']['#ajax'] = array( 'callback' => '...
0
votes
0answers
15 views

Prevent webform from submitting when clicking button in markup component

I have a very complex webform in a Drupal 7 website I've inherited. I have added a markup component which builds a button and added some JS that links this button to trigger a modal window to open. In ...
2
votes
1answer
103 views

CSRF token is not varying in Ajax callback while submitting form

I have a form with ajax callback as following , on each submit token is not varying , it remains constant for all submit . wall.routing.yml wall.commentform: path: '/commentform' defaults: ...
1
vote
0answers
67 views

Using a #submit callback on a textfield

We have a need to add 'repeatable fields' to a form based on input provided in a textfield. Usually, we use a 'add another' button to keep track of the number of fields to render in the buildForm(), ...
0
votes
1answer
42 views

Proper way to get input field value with AJAX

I want to do some calculations in node edit form vith ajax. Form fields is created via UI, so i need to drill into field array to get value(s). Maximum result what i have is replacing target field ...
0
votes
1answer
58 views

Ajax Callback only works after second click

I created a custom form with a textbox and a button. When the user clicks on that button, an ajax call should take place. When I click on that button for the first time, a page refresh takes place. ...
0
votes
1answer
30 views

How do I pass a context filter to a block loaded by ajax?

There is a block created in views that displays the values of the taxonomy term fields. This block should be loaded when selecting a term from the select field in a custom form. Accordingly, the block ...
0
votes
1answer
53 views

Custom Submit Button On Inline Entity Form Triggers Gives Wrong Triggering Element

I have implemented hook_field_widget_form_alter() to add a new #process array item. E.g. hook_field_widget_form_alter() { $element['#process'][] = ['custom_process_function']; } This part works ...
0
votes
1answer
18 views

how to call handler on every ajax request

I have created a handler for every submit request using $form['#submit'][] = 'MYMODULE_form_submit_handler' now the problem is this doesnt works on Ajax submit, or page call backs functions. i want to ...
1
vote
1answer
119 views

Behavior to use .insertAfter() on load + after each ajax call?

So I have a views page that outputs some elements in the grid. And I have a custom block on the page that needs to be inserted between those elements. On load it using .insertAfter() to randomly ...
0
votes
0answers
40 views

Loading form by Ajax and Submit by Ajax

This question is asked few times but I am still lost on my solution. I did check this but couldn't make my code work. My my_module.routing.yml entity.node.my_module_form.node: path: '/contribute/{...
0
votes
0answers
37 views

Error "not valid choice" when dropdown populated using ajax [duplicate]

I've searched the other similar answer but still no luck. I have content type Station with field Province and City. Form alter: function mymodule_form_alter(&$form, FormStateInterface $form_state, ...
0
votes
0answers
27 views

How to render Messages in an AjaxResponse? [duplicate]

I have a modal form which when submitted calls submitModalFormAjax(). I am trying to get the messages that were previously created and use an AjaxResponse command to print the messages to the modal's ...
2
votes
0answers
170 views

Multiple dependent form fields

I'm building a form following the ajax examples module, specifically the dependent dropdown form. I've tried the same approach as the example, calling a static function to retrieve the options for the ...

1
2 3 4 5
50