Change checkbox to boolean select menu

This commit is contained in:
Preston Doman 2019-02-14 14:17:25 -08:00
parent b052bfea3c
commit f2f1a3399b
2 changed files with 20 additions and 21 deletions

View file

@ -162,13 +162,10 @@ def section(request, report_pk, section_pk):
if update.field_type == "boolean":
# flight check
if request.data[key] == "on":
if request.data[key] == "true":
update.data_bool = True
elif request.data[key] == "off":
elif request.data[key] == "false":
update.data_bool = False
# everything else
else:
update.data_bool = request.data[key]
if update.field_type == "decimal":
# initialize to 0

View file

@ -74,22 +74,24 @@ function createFormGroup(field) {
switch(field.field_type) {
case "boolean":
input.type = "checkbox";
if (field.value === true)
input.setAttribute("checked", "checked");
input.classList.add("form-check-input");
label.className = "";
label.classList.add("form-check-label");
label.innerHTML = field.label;
outerLabel = document.createElement("div");
outerLabel.classList.add("col-sm-4");
outerLabel.innerHTML = "Flight type: ";
formCheck = document.createElement("div");
formCheck.classList.add("form-check");
formCheck.appendChild(input);
formCheck.appendChild(label);
div.appendChild(formCheck);
formGroup.appendChild(outerLabel);
const select = document.createElement("select");
select.name = field.field_name;
select.classList.add("form-control");
const yesOption = document.createElement("option");
yesOption.innerHTML = "Yes";
yesOption.value = "true";
const noOption = document.createElement("option");
noOption.innerHTML = "No";
noOption.value = "false";
if (field.value === true) {
yesOption.setAttribute("selected", "selected");
} else {
noOption.setAttribute("selected", "selected");
}
select.appendChild(yesOption);
select.appendChild(noOption);
formGroup.appendChild(label);
div.appendChild(select)
formGroup.appendChild(div);
break;
case "date":