diff --git a/caimira/apps/calculator/static/js/co2_form.js b/caimira/apps/calculator/static/js/co2_form.js index eb019c5b..afcf7638 100644 --- a/caimira/apps/calculator/static/js/co2_form.js +++ b/caimira/apps/calculator/static/js/co2_form.js @@ -154,8 +154,8 @@ function validateFormInputs(obj) { const $referenceNode = $("#DIVCO2_data_dialog"); for (let i = 0; i < CO2_data_form.length; i++) { const $requiredElement = $(`[name=${CO2_data_form[i]}]`).first(); - if ($requiredElement.attr('name') !== "fitting_ventilation_states" && - $requiredElement.attr('name') !== "room_capacity" && + if ($requiredElement.attr('name') !== "fitting_ventilation_states" && + $requiredElement.attr('name') !== "room_capacity" && $requiredElement.val() === "") { insertErrorFor( $referenceNode, @@ -245,7 +245,6 @@ function validateCO2Form() { const roomCapacityVal = roomCapacity.val(); if (roomCapacityVal !== "") { const roomCapacityNumber = Number(roomCapacityVal); - const totalPeopleNumber = Number($("#total_people").val()); if (!Number.isInteger(roomCapacityNumber) || roomCapacityNumber <= 0) { insertErrorFor( $referenceNode, @@ -255,11 +254,7 @@ function validateCO2Form() { } } else { - insertErrorFor( - $referenceNode, - `'${roomCapacity.attr('name')}' must be defined.` - ); - submit = false; + $fittingToSubmit.find("#warning_room_capacity_null").show(); } } @@ -286,6 +281,10 @@ function displayFittingData(json_response) { // Not needed for the form submission delete json_response["CO2_plot"]; delete json_response["predictive_CO2"]; + // Convert nulls to empty strings in the JSON response + if (json_response["room_capacity"] === null) json_response["room_capacity"] = ''; + if (json_response["ventilation_lsp_values"] === null) json_response["ventilation_lsp_values"] = ''; + // Populate the hidden input $("#CO2_fitting_result").val(JSON.stringify(json_response)); $("#exhalation_rate_fit").html( "Exhalation rate: " + @@ -295,10 +294,14 @@ function displayFittingData(json_response) { let ventilation_table = `
From fitting: {% if form.ventilation_type == "from_fitting" %} Yes
-Room capacity: {{ form.CO2_fitting_result['room_capacity'] | int_format }}
Room capacity: {{ form.CO2_fitting_result['room_capacity'] | int_format }}
| Time (HH:MM) | ACH value (h⁻¹) | Flow rate (L/s) | -Flow rate (L/s/person) | + {% if form.CO2_fitting_result['room_capacity'] %}Flow rate (L/s/person) | {% endif %}{{ transition_time[loop.index - 1] | hour_format }} - {{ transition_time[loop.index] | hour_format }} | {{ ventilation | float_format }} | {{ form.CO2_fitting_result['ventilation_ls_values'][loop.index - 1] | float_format }} | -{{ form.CO2_fitting_result['ventilation_lsp_values'][loop.index - 1] | float_format }} | + {% if form.CO2_fitting_result['room_capacity'] %}{{ form.CO2_fitting_result['ventilation_lsp_values'][loop.index - 1] | float_format }} | {% endif %} {% endfor %}
|---|