Commit 0ffecd03 authored by Hans-Peter Deifel's avatar Hans-Peter Deifel

upload: Send correct form data in presence of checkboxes

tl;dr: Unchecked checkboxes usually don't send their value as
parameter when the form is submitted. The ajax request in our upload
code did just that which resulted in the value of checkboxes being
wrongly interpreted.

The default value of a checkbox is "on", even when it is off. The crux
is that with standard HTML forms, this value will only be included in
the form data if the checkbox is checked. The python end thus receives
"on" for a checked checkbox and the empty string for an unchecked
checkbox. It so happens that bool("on") == True and bool("") == False.

Our JavaScript code that sends the form data for the upload page
wrongly included the checkbox value, even if it was not checked. This
resulted in the python end always receiving "on".

See: http://stackoverflow.com/questions/33487360/formdata-and-checkboxes

fixes #106
parent 3ceabebc
......@@ -33,11 +33,7 @@
sm[i].disabled = true;
var xhr = new XMLHttpRequest();
xhr.open(form.method, form.action);
var data = new FormData();
for(var i=0; i < form.elements.length; i++) {
if(form.elements[i].type == 'submit') continue;
data.append(form.elements[i].name, form.elements[i].value);
}
var data = new FormData(form);
data.append(ev.target.name, ev.target.value);
xhr.onloadend = function(ev) {
if(xhr.status == 200) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment