Questions tagged [ajax]

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

Filter by
Sorted by
Tagged with
0
votes
1answer
22 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
42 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
22 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
38 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
29 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
32 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
32 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
28 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
12 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
28 views

Is it possible to change the checkbox options after the autocomplete event?

Is it possible to change the checkbox options after the autocomplete event? I created a checkboxes form element with autocomplete. I need to change checkbox options dynamically based on the ...
0
votes
0answers
23 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
0answers
40 views

How to get the previous dynamic value generated by autocomplete?

I added an AJAX "Add more" button in a form. After the autocomplete event, I replace some text. It works only the first time; the other times, the first value is removed. namespace Drupal\...
1
vote
1answer
15 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
0answers
54 views

How to have AJAX callback after an autocomplete on paragraph with conditional fields?

I have 2 fields, both of which are in paragraphs (in different paragraphs). Essentially what I'm trying to do is : Once the autocomplete is finished on Field Facility on Paragraph Facility, I would ...
1
vote
1answer
73 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
16 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 ...
1
vote
1answer
45 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
34 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'] = [ '...
0
votes
1answer
45 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
31 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
94 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 ...
1
vote
0answers
42 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
82 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
23 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
23 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
13 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
76 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
58 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
28 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
57 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
25 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
32 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
16 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 ...
2
votes
1answer
77 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
28 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
34 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, ...
1
vote
0answers
26 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
111 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 ...
4
votes
1answer
66 views

How to add an autocomplete field with pure javascript

I'm implementing the javascript library Annotorious which allow to add annotations on an image. My goal is to be able to link content with part of the image select with Annotorious. When we select a ...
1
vote
0answers
59 views

How to render a view in an ajax callback

I am trying to develop a custom module to ajaxify the commerce form block. I tried using dc_ajax_add_cart and ajax_add_to_cart but they were not addapted to my project. I have the following callback ...
0
votes
0answers
29 views

Load page content with AJAX after being gated

I need to gate a page's content with a form so that the content isn't loaded until a form on the frontend is filled out. I can hook into this form's onSuccess method (all via JavaScript) but I'm a bit ...
0
votes
0answers
16 views

I want to run checking code on Ubercart product attribute

I want to run checking code on a Ubercart product field attribute before allowed to proceed with the checkout. The code could run right below or in conjunction with the "required" - not ...
1
vote
1answer
53 views

Ajax enabled form stopped working - Ajax callback never called

I have the weird problem that an Ajax enabled form that just worked stopped working - and I have not a clue what is causing this and when it stopped to work. The form itself has no changes for months ...
-3
votes
2answers
34 views

Set a default integer value with #ajax, according to a form state value in the same form

There is an integer field: "Number of pitches" Another integer field: "Maximum people allowed". These will usually be the same values. I am trying to set the value of the field ...
0
votes
1answer
88 views

How to deal with block cached for anonymous user?

I have placed in the site's home, via twig, a views block of nodes with a random sort and obliviously no cache active. Therefore, at each page reload different nodes appear. The problem is that block ...
0
votes
1answer
54 views

Inline Javascript throws an error on drupal_add_js() within an AJAX callback

I am trying to get JavaScript to measure a text field and auto submit at a character limit for an Ajax callback to be validated against a Luhn Algorithm and errors out on failure to validate. I found ...
0
votes
0answers
27 views

One Dependent dropdown in an other, the second getvalue does not return anything

I create one dependent dropdown into an other with ajax. My configuration that I have cleaned up here works and I want to add the condition on the date options: if option is 'before the', i display ...
0
votes
0answers
19 views

I've altered the exposed filters how I want them in hook_views_pre_build(). How do I retain those settings after an AJAX filter is used?

In Drupal 7, I have a content type that displays a content view within it. This view display contains 4 exposed filters. On the content type, I have a custom select field which allows the author to ...
0
votes
1answer
34 views

How do I redirect to the login page?

I have a custom search form which appears in the modal and is accessible only to logged in users. The ajax url of the form is /my/custom/search/modal/{nojs}. The router definition is the following one....
0
votes
0answers
20 views

Form doesn't update via hook in edit mode, instead of it page reloading

This is not happening all time (possibly for big amount of existing field, I'm not sure, with less amount of fields form is saving as it should) when I'm adding new Field collection entity or update ...

1
2 3 4 5
50