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

[WiP] Fix: Use form.ajaxSubmit() instead of jQuery.ajax() (fixes FileField in CMS) #583

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 6 additions & 7 deletions client/src/legacy/LeftAndMain.js
Expand Up @@ -473,15 +473,15 @@ $.entwine('ss', function($) {
clearButton();
}

// get all data from the form
var formData = form.serializeArray();
// collect extra form data, the form data itself is collected by .ajaxSubmit()
var extraFormData = {};
// add button action
formData.push({name: $(button).attr('name'), value:'1'});
extraFormData[$(button).attr('name')] = '1';
// Artificial HTTP referer, IE doesn't submit them via ajax.
// Also rewrites anchors to their page counterparts, which is important
// as automatic browser ajax response redirects seem to discard the hash/fragment.
// TODO Replaces trailing slashes added by History after locale (e.g. admin/?locale=en/)
formData.push({ name: 'BackURL', value: document.URL.replace(/\/$/, '') });
extraFormData.BackURL = document.URL.replace(/\/$/, '');

// Save tab selections so we can restore them later
this.saveTabState();
Expand All @@ -491,10 +491,9 @@ $.entwine('ss', function($) {
// The returned view isn't always decided upon when the request
// is fired, so the server might decide to change it based on its own logic,
// sending back different `X-Pjax` headers and content
jQuery.ajax(jQuery.extend({
form.ajaxSubmit(jQuery.extend({
headers: {"X-Pjax" : "CurrentForm,Breadcrumbs"},
url: form.attr('action'),
data: formData,
data: extraFormData,
type: 'POST',
complete: function() {
clearButton()
Expand Down