Переглянути джерело

fix: fixed issue that when a variable is created or deleted all variable selects aren't being updated

Marcelo Vilas Boas Correa Filho 3 роки тому
батько
коміт
1adc342ff8
1 змінених файлів з 23 додано та 0 видалено
  1. 23 0
      js/accessibleUI/modules/variables/variables.js

+ 23 - 0
js/accessibleUI/modules/variables/variables.js

@@ -52,6 +52,7 @@ export function createVariable () {
     });
 
     updateResume(variable.hash);
+    updateAllVariableSelect();
 
     // Changing focus to the variable type after creation for screen readers
     document.getElementById(`variable${variable.hash}Type`).focus();
@@ -99,6 +100,8 @@ export function deleteVariable (hash) {
 
     deleteOperationByVariable(variable);
     variables.splice(variables.indexOf(variable), 1);
+
+    updateAllVariableSelect();
 }
 
 // Deleting all variable
@@ -124,6 +127,26 @@ function generateResume (hash) {
     return `${variable.type.name} ${variable.name} recebe ${variable.value}`;
 }
 
+// ***********************************************************************
+// Update all variable select
+// **********************************************************************
+
+function updateAllVariableSelect () {
+    const variableSelects = document.getElementsByName('variableSelect');
+
+    let variablesSelect = variables.length === 0 ? `<option>N/A</option>` : ``;
+
+    for (let i = 0; i < variables.length; i++) {
+        variablesSelect += `<option value="${variables[i].hash}">${variables[i].name}</option>`
+    }
+
+    for (let i = 0; i < variableSelects.length; i++) {
+        const selectedOption = variableSelects[i].value;
+        variableSelects[i].innerHTML = variablesSelect;
+        variableSelects[i].value = selectedOption;
+    }
+}
+
 // *********************************************************************************
 // Util
 // *********************************************************************************