Browse Source

Reworked Objective OutcomeSelect

eduardo-santin 3 years ago
parent
commit
b3ac5c8b02
1 changed files with 20 additions and 12 deletions
  1. 20
    12
      app/views/local/managers/pCoords/objectives.blade.php

+ 20
- 12
app/views/local/managers/pCoords/objectives.blade.php View File

@@ -294,10 +294,17 @@
294 294
     function addOutcomeTest() {
295 295
         var $select = $('<select/>', {
296 296
             'class': "selectpicker form-control",
297
-            'name': "outcome[" + counter.toString() + "]",
297
+            'name': "outcome[' + counter.toString() + ']",
298 298
             'data-live-search': 'true'
299 299
 
300 300
         });
301
+
302
+        //holds both the select div and the button div
303
+        var $containerdiv = $('<div/>', {
304
+            'id': 'outcomeContainer' + counter.toString(),
305
+        });
306
+
307
+
301 308
         var $div = $('<div/>', {
302 309
             'id': 'outcomeForm' + counter.toString(),
303 310
             'class': 'form-group col-md-11'
@@ -307,32 +314,33 @@
307 314
             'id': 'close' + counter.toString()
308 315
 
309 316
         });
317
+
310 318
         var $button = $('<button/>', {
311 319
             'type': 'button',
312 320
             'class': 'btn btn-primary',
313
-            'onclick': 'deleteLast()'
321
+
322
+            //send the counter to the function so it can tell which container to remove
323
+            'onclick': 'deleteLast(' + counter.toString() + ')',
324
+            
314 325
         });
315 326
         $button.append('X');
316 327
         $divForButton.append($button);
317 328
 
318
-        $div.appendTo('#outcomeGroup')
329
+        $containerdiv.appendTo('#outcomeGroup')
330
+        $div.appendTo('#outcomeContainer' + counter.toString())
319 331
         $select.append(selectOptions);
320 332
 
321 333
         $select.appendTo('#outcomeForm' + counter.toString()).selectpicker('refresh');
322
-        $divForButton.appendTo('#outcomeGroup');
334
+        $divForButton.appendTo('#outcomeContainer' + counter.toString());
323 335
         counter += 1;
324 336
         $('#counter').val(counter);
325 337
 
326 338
     }
327
-
328
-    function deleteLast() {
329
-
330
-        div = document.getElementById('outcomeForm' + (counter - 1).toString());
339
+    
340
+    //Recieves the counter variable so it can find the specific div and delete it
341
+    function deleteLast(counter) {
342
+        div = document.getElementById('outcomeContainer' + (counter).toString());
331 343
         div.remove();
332
-        button = document.getElementById('close' + (counter - 1).toString());
333
-        button.remove();
334
-        counter -= 1;
335
-        $('#counter').val(counter);
336 344
     }
337 345
 
338 346
     function fetchObjectiveForEditing() {