Basically, when creating a FormData object from a form that has no
inputs to be sent (inputs that are disabled, inputs without name and
unchecked checkboxes/radio buttons are generally not included in a form
request) and sending that as the body for a XMLHttpRequest, it will
result in a corrupt multipart request. Unfortunately there is poor support for
iterating a FormData object to find out if it is empty (at least it did
not work in PhantomJS).
This fix tries to predict if the FormData object will be empty by
inspecting the form elements. If it can find no form input that will be
included in the request, the data is nullified before passing it to
LiteAjax.ajax().
Fix for hauleth/vanilla-ujs #28. For the full bug report please refer to https://github.com/hauleth/vanilla-ujs/issues/28.
Basically, when creating a FormData object from a form that has no inputs to be sent (inputs that are disabled, inputs without name and unchecked checkboxes/radio buttons are generally not included in a form request) and sending that as the body for a XMLHttpRequest, it will result in a corrupt multipart request. Unfortunately there is poor support for iterating a FormData object to find out if it is empty (at least it did not work in PhantomJS).
This fix tries to predict if the FormData object will be empty by inspecting the form elements. If it can find no form input that will be included in the request, the data is nullified before passing it to
LiteAjax.ajax()
.