All files / app/assets/javascripts/ci_variable_list native_form_variable_list.js

100% Statements 9/9
33.33% Branches 1/3
100% Functions 2/2
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26          1x   1x       1x       1x 1x   1x 1x 1x 1x        
import $ from 'jquery';
import VariableList from './ci_variable_list';
 
// Used for the variable list on scheduled pipeline edit page
export default function setupNativeFormVariableList({ container, formField = 'variables' }) {
  const $container = $(container);
 
  const variableList = new VariableList({
    container: $container,
    formField,
  });
  variableList.init();
 
  // Clear out the names in the empty last row so it
  // doesn't get submitted and throw validation errors
  $container.closest('form').on('submit trigger-submit', () => {
    const $lastRow = $container.find('.js-row').last();
 
    const isTouched = variableList.checkIfRowTouched($lastRow);
    Eif (!isTouched) {
      $lastRow.find('input, textarea').attr('name', '');
      $lastRow.find('select').attr('name', '');
    }
  });
}