Submitting a form during an ajax request: field data not in $_POST.

Created on 17 August 2012, over 12 years ago
Updated 7 September 2023, over 1 year ago

Problem/Motivation

I have a form with a textfield element with an ajax callback. I use the ajax callback to display possible duplicate nodes.

Whenever the value of the textfield changes, an ajax request is triggered and the element will be temporarily disabled untill the ajax request finishes. The change event is triggered when the texfield loses focus and its value was changed.

If I submit the form during the ajax request, the value of the textfield will not be submitted and its old value will be used. This happens if I select the textfield, change its value and then directly click the save button of the form.

The reason AJAX elements are disabled, is to prevent the user from changing the element's value during the request. Ideally we should make the element readonly but the readonly property isn't available for all input elements. The current implementation uses the jQuery Form plugin's options.extraData to post the data of the disabled field. This works fine if there's only
one active ajax request.

Steps to reproduce

TBA

Proposed resolution

The solution I propose is to create a hidden input element for any ajax-disabled element and remove it when the ajax event finishes.

Remaining tasks

Confirm the solution
Review
Commit

User interface changes

API changes

Data model changes

Release notes snippet

๐Ÿ› Bug report
Status

Needs review

Version

9.5

Component
Ajaxย  โ†’

Last updated about 19 hours ago

Created by

๐Ÿ‡ง๐Ÿ‡ชBelgium kenneth.venken

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • last update over 1 year ago
    Custom Commands Failed
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium jelle_s Antwerp, Belgium

    Reroll against 10.1.x

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    #49 called for issue summary update which believe still needs to happen.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia gauravvvv Delhi, India

    Fixed, CCF in #55. Attached interdiff for same. leaving as NW, as issue summary still needs to update.

  • last update over 1 year ago
    30,147 pass
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States capysara

    I updated the IS and title based on the discussion to date and my assessment of the issue. The summary of my summary is: there isnโ€™t sufficient support for the original proposed solution as a core fix, but there is overall support and arguments in favor of disabling the submit button.

    I agree with #34 that there are 2 separate issues here.

    I think that submit should be disabled so that the form canโ€™t be submitted while the ajax change call is running and before the server has responded. If you're going all the way to the server for a change event, it's probably important that it finishes and, if that's the case, the submit button should be disabled until the form is ready to be interacted with again. Since the ajax change call response can modify the values in the form, the user should not be able to submit the form with just the values they provided in the field (e.g., entity reference fields that rely on ajax change events).

    However, I donโ€™t think that disabling the submit button addresses the reported issue and, IMO, would unnecessarily expand the scope of this ticket.

    The problem described here is that the change event isnโ€™t triggered until the text field loses focus, which can cause data loss because a user can submit the form without losing focus on the field, but before ajax ever runs. In other words, the form gets submitted, but ajax was never triggered, so the value isnโ€™t saved.

    I think that further discussion should be around determining what type of event should be used to fire the ajax change.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States capysara
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States brad.bulger

    Reroll of patch in #57 for 10.3.x

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium JeroenT ๐Ÿ‡ง๐Ÿ‡ช

    Patch #61 doesn't contain all newly added files.

Production build 0.71.5 2024