Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS-evaluation in ajax-enabled forms #7203

Open
asaage opened this issue May 8, 2024 · 7 comments
Open

JS-evaluation in ajax-enabled forms #7203

asaage opened this issue May 8, 2024 · 7 comments
Labels
bug up for discussion Issues and PRs which will be discussed in our monthly Mumble calls.
Milestone

Comments

@asaage
Copy link

asaage commented May 8, 2024

Affected version(s)

5.3.7

Description

When a form is ajax enabled, script-tags are not loaded and executed (exept in the initial page-load).
Not sure, if that is by design, a known limitation or just a missing eval(); somewhere.
It occured first to me in a mp_form but the problem seems to be in the xhr-handler.
Such a script-tag exists especially in the captcha-field/widget (maybe others too).
To recreate: make a form, enable ajax, add an email-field, a captcha-field and a submit. In the FE force a validation error by submitting example@foo (mailaddress without tld). As a result the form will return with the usual errormessage but the captcha-field will be visible and not hidden as usual.

related:

@fritzmg
Copy link
Contributor

fritzmg commented May 28, 2024

I can confirm the issue.

@fritzmg fritzmg added this to the 5.3 milestone May 28, 2024
@fritzmg fritzmg added up for discussion Issues and PRs which will be discussed in our monthly Mumble calls. and removed unconfirmed labels May 28, 2024
@ausi
Copy link
Member

ausi commented May 28, 2024

To fix this we should IMO not evaluate the <script>s of the ajax response, but instead add an ajax-form-onload event listener to the captcha script.

@fritzmg
Copy link
Contributor

fritzmg commented May 28, 2024

Or may be implement it as a mutation observer instead?

@asaage
Copy link
Author

asaage commented May 28, 2024

... add ... event listener to the captcha script.

I would prefer if a solution does not depend on a special widget.
If you add js to other widgets (like for example displaying the value of a range-slider) you would face the same problem again.

@fritzmg
Copy link
Contributor

fritzmg commented May 28, 2024

@asaage The solution will be done within the captcha widget's JavaScript. And any other widget of course needs to implement their JavaScript in a way that is independent from whether the form is submitted via AJAX or not (and that has always been the case).

@asaage
Copy link
Author

asaage commented May 28, 2024

i figure, that would probably not solve the original issue i had in mp_forms and complicate enhancing formfield templates with js unneccessary 🤷‍♂️

@fritzmg
Copy link
Contributor

fritzmg commented May 28, 2024

that would probably not solve the original issue i had in mp_form

May be ask on the Contao Community Forum or Community Slack for help regarding that issue.

and complicate enhancing formfield templates with js unneccessary 🤷‍♂️

I am not sure what you mean here. May be also ask on the Contao Community Forum or Community Slack for advice on how to handle forms that are submitted via AJAX properly (this is a general topic unrelated to Contao itself).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug up for discussion Issues and PRs which will be discussed in our monthly Mumble calls.
Projects
None yet
Development

No branches or pull requests

3 participants