Skip to content

Commit

Permalink
Fix bug in Safari where XHR form submission fails with empty file inp…
Browse files Browse the repository at this point in the history
…ut (#4673)

* Provides a fix for a bug in Safari where XHR form submission fails when input[type=file] is empty
  • Loading branch information
erikvdplas authored and stennie committed Jun 30, 2018
1 parent e6993f2 commit 1e458db
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions admin/client/App/screens/Item/components/EditForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,19 @@ var EditForm = React.createClass({
updateItem () {
const { data, list } = this.props;
const editForm = this.refs.editForm;

// Fix for Safari where XHR form submission fails when input[type=file] is empty
// https://stackoverflow.com/questions/49614091/safari-11-1-ajax-xhr-form-submission-fails-when-inputtype-file-is-empty
$(editForm).find("input[type='file']").each(function () {
if ($(this).get(0).files.length === 0) { $(this).prop('disabled', true); }
});

const formData = new FormData(editForm);

$(editForm).find("input[type='file']").each(function () {
if ($(this).get(0).files.length === 0) { $(this).prop('disabled', false); }
});

// Show loading indicator
this.setState({
loading: true,
Expand Down

0 comments on commit 1e458db

Please sign in to comment.