diff options
Diffstat (limited to 'app/assets/javascripts/ci/ci_variable_list/native_form_variable_list.js')
-rw-r--r-- | app/assets/javascripts/ci/ci_variable_list/native_form_variable_list.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/app/assets/javascripts/ci/ci_variable_list/native_form_variable_list.js b/app/assets/javascripts/ci/ci_variable_list/native_form_variable_list.js new file mode 100644 index 00000000000..fdbefd8c313 --- /dev/null +++ b/app/assets/javascripts/ci/ci_variable_list/native_form_variable_list.js @@ -0,0 +1,25 @@ +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); + if (!isTouched) { + $lastRow.find('input, textarea').attr('name', ''); + $lastRow.find('select').attr('name', ''); + } + }); +} |