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
     function addOutcomeTest() {
294
     function addOutcomeTest() {
295
         var $select = $('<select/>', {
295
         var $select = $('<select/>', {
296
             'class': "selectpicker form-control",
296
             'class': "selectpicker form-control",
297
-            'name': "outcome[" + counter.toString() + "]",
297
+            'name': "outcome[' + counter.toString() + ']",
298
             'data-live-search': 'true'
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
         var $div = $('<div/>', {
308
         var $div = $('<div/>', {
302
             'id': 'outcomeForm' + counter.toString(),
309
             'id': 'outcomeForm' + counter.toString(),
303
             'class': 'form-group col-md-11'
310
             'class': 'form-group col-md-11'
307
             'id': 'close' + counter.toString()
314
             'id': 'close' + counter.toString()
308
 
315
 
309
         });
316
         });
317
+
310
         var $button = $('<button/>', {
318
         var $button = $('<button/>', {
311
             'type': 'button',
319
             'type': 'button',
312
             'class': 'btn btn-primary',
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
         $button.append('X');
326
         $button.append('X');
316
         $divForButton.append($button);
327
         $divForButton.append($button);
317
 
328
 
318
-        $div.appendTo('#outcomeGroup')
329
+        $containerdiv.appendTo('#outcomeGroup')
330
+        $div.appendTo('#outcomeContainer' + counter.toString())
319
         $select.append(selectOptions);
331
         $select.append(selectOptions);
320
 
332
 
321
         $select.appendTo('#outcomeForm' + counter.toString()).selectpicker('refresh');
333
         $select.appendTo('#outcomeForm' + counter.toString()).selectpicker('refresh');
322
-        $divForButton.appendTo('#outcomeGroup');
334
+        $divForButton.appendTo('#outcomeContainer' + counter.toString());
323
         counter += 1;
335
         counter += 1;
324
         $('#counter').val(counter);
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
         div.remove();
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
     function fetchObjectiveForEditing() {
346
     function fetchObjectiveForEditing() {