Questions tagged [ajax]

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

Filter by
Sorted by
Tagged with
-1
votes
0answers
9 views

Render form elements by ajax

This is working fine, but i need to render too many fields inside in ajax call with states check to show and hide fields. So i m using '#states' but it is not working, in following ajax call it gives ...
1
vote
1answer
74 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
15 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
17 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
12 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
45 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
50 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
24 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
55 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
19 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
0answers
19 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
13 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
34 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
25 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
24 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
91 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
55 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
39 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
26 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
42 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
31 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
77 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
53 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
18 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
28 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 ...
0
votes
0answers
37 views

An AJAX HTTP error occurred during the Drupal module update

On Druapl 9.1.5, during the Metatag 8.x-1.16 update from the site it gave the following: Debugging information follows. Path: /core/authorize.php/core/authorize.php?batch=1&id=477&op=do_nojs&op=do ...
0
votes
0answers
20 views

Php Error Media Library Add button not working?

I have imported config files of content types, paragraph from my site to other site. Media Library Config files are also available. Enabled the Media Library module and imported the config files. ...
0
votes
1answer
35 views

Dependent dropdown into an Ajax AddMore

I used a dependent dropdown into an Ajax AddMore, so I checked the code of Ajax Examples, class AjaxAddMore and more. I have several versions that all have a problem; on this one, the behavior of the ...
0
votes
0answers
18 views

Firing custom submit on ajax form works with #ajax_processed set, but reloads the page

I'm placing a subform within the node edit form using a form_alter where I build the subform and add it to the form array. My subform has a custom submit handler and '#ajax' is set: $form['...
0
votes
1answer
31 views

How to get the row added by ajax in the right place?

I have a table form created from a custom entity: public function buildForm(array $form, FormStateInterface $form_state, $contract = NULL) { $form['subscriptions'] = [ '#type' =&...
0
votes
0answers
35 views

AjaxResponse() always wrapped in a <textarea>

In a custom controller, I'm returning an AjaxResponse like so: $response = new AjaxResponse(); $selector = '.segment-set-wrapper'; $response->addCommand(new ReplaceCommand($selector, $...
1
vote
0answers
13 views

Dynamically added params for a link not found when the link is opened with a dialog

I do not know if it has to do with JavaScript/Ajax or with Drupal's dialog modal. Any advice is appreciated. On our project we open several links in a modal. For this the link is rendered in the ...
0
votes
1answer
22 views

How to display a field when a media is uploaded to the media library field?

I have block settings form where I have a media library field. public function blockForm($form, FormStateInterface $form_state) { $form = parent::blockForm($form, $form_state); $user_input = $...
0
votes
0answers
18 views

Ajax callback to create paragraphs on form

I'm trying to create a way that an end user can upload a csv into a node form and it automatically extracts the content and then creates paragraphs in the form. I have created a custom managed file ...
0
votes
1answer
31 views

How to display messages “properly” when using ajax submit?

Here is a simple form: public function buildForm(array $form, FormStateInterface $form_state) { $form['some_text'] = [ '#type' => 'textfield', '#title' => $this->t('...
0
votes
0answers
65 views

How to add a throbber to a submit button in a form?

In a custom module, I have a form with a simple submit button: $form['submit'] = [ '#type' => 'submit', '#value' => $this->t('Submit'), ]; As the execution of the code in submitForm ...
3
votes
1answer
42 views

Ajax table form with tabledrag only works properly AFTER first submit

So this one has me kind of stumped. With a simple table with 4 rows, I drag one row to another position, then hit save (submit). When the ajax returns and replaces the form, the rows snap back to the ...
0
votes
0answers
24 views

Form element with dynamic autocomplete route parameter

I have a simple form with two fields and a button. A field for the text to search and a field to select a type of node. The search text field has a autocomplete route that shows a list of nodes, but I ...
0
votes
3answers
108 views

How can I send an HTML email from an Ajax callback? [closed]

I want to send an email to the user who forget username. I created a functionality that handle with Ajax like send request to controller where I using a query to check whether user exist or not. if ...
0
votes
0answers
42 views

Ajax HtmlCommand not working on form field in a field group

I've added a custom ajax callback to a field that I'm trying to update the value of. The Field I'm updating is inside a field group and instead of updating the field it just empties the html. The form ...
0
votes
0answers
24 views

Can't upload anonymously using webform

I am using varbase 9.0.0-rc1 distribution I have successfully uploaded files using the forms while I am logged in. But anonymously I get the following error: An error occurred while attempting to ...
1
vote
1answer
39 views

Can't submit entityform after ajax callback on select element

I followed the advice from this link and migrated the code populating my ajax into buildForm(), and all is well. Select list is populated by ajax and elements are preserved even after form submit. ...
1
vote
0answers
34 views

Drupal Form code is called again on every ajax Call?

I have a form and i call an API tahta brings huge data on build form. But when i call Ajax on other form elements , the whole code for form(buildForm, constructor ) is called again and again. There ...
1
vote
0answers
43 views

Updating modules creates An AJAX HTTP request terminated abnormally error

Drupal 7.77. I have three modules that need to be updated. Trying to update any one of them results in this error: An AJAX HTTP request terminated abnormally. Debugging information follows. Path: ...
0
votes
1answer
97 views

Ajax Callback to Update Select List not Working

I have defined couple of fields inside my custom entity basefielddefinitions() like so... $fields['product_line'] = BaseFieldDefinition::create('entity_reference')... $fields['product'] = ...
0
votes
0answers
136 views

Passing data-dialog-options and data-dialog-type dynamically to an <a> tag not opening modal

I'm trying to create a dynamic way to open a modal window in drupal. The current structure work like this. <a class="use-ajax" href="/node/810">Testing 1 </a> For that ...

1
2 3 4 5
49