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": if update.field_type == "boolean":
# flight check # flight check
if request.data[key] == "on": if request.data[key] == "true":
update.data_bool = True update.data_bool = True
elif request.data[key] == "off": elif request.data[key] == "false":
update.data_bool = False update.data_bool = False
# everything else
else:
update.data_bool = request.data[key]
if update.field_type == "decimal": if update.field_type == "decimal":
# initialize to 0 # initialize to 0

View file

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