Fixed JS: Can't prevent form from being submitted

TnT

Member
Affected version
2.3.0 Beta 2
I am in the process of rewriting one of my addons, as jquery is no longer used. A modal should be displayed as soon as attachments are uploaded to a post. Sending the form with the message should be prevented until the modal dialog is confirmed with "ok".

And this is exactly where my problem lies. I can no longer prevent the form from being sent.

I have looked at this area (row 145) in the Attachment Manager (/js/xf/attachment_manager.js):
JavaScript:
                XF.on(this.form, 'ajax-submit:before', data =>
                {
                    if (this.isUploading && !confirm(XF.phrase('files_being_uploaded_are_you_sure')))
                    {
                        data.preventSubmit = true
                    }
                })

Here, for example, the form should be prevented from being sent while files are still being uploaded.

If I comment out the if query here, for example, the form should generally be prevented from being sent. However, it is sent anyway. Even a data.preventDefault(); did not help.

JavaScript:
                XF.on(this.form, 'ajax-submit:before', data =>
                {
                    // if (this.isUploading && !confirm(XF.phrase('files_being_uploaded_are_you_sure')))
                    // {
                        data.preventSubmit = true
                        data.preventDefault();
                    // }
                })
 
I have now managed it by listening to the two events "submit ajax-submit:before" at the same time. However, I don't find this very exciting.
 
Tried it and didn't worked for me.

For my usecase this works:
JavaScript:
    XF.on(document, 'submit ajax-submit:before', (e) =>
    {
            e.preventDefault()
            e.preventSubmit = true
    }
 
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.3.0 Beta 6).

Change log:
Fix AJAX form submission event inhibiton
There may be a delay before changes are rolled out to the XenForo Community.
 
Top Bottom