diff --git a/assets/mod/modForm.js b/assets/mod/modForm.js index 9e837aab..6309525a 100644 --- a/assets/mod/modForm.js +++ b/assets/mod/modForm.js @@ -8,42 +8,28 @@ modForm.TYPE_CLIENT_SIDE = 'client_side'; modForm.SOURCE_STEAM_WORKSHOP = 'steam_workshop'; modForm.SOURCE_DIRECTORY = 'directory'; -modForm.onModTypeChange = () => { - const $type = $('#mod_form_type'); - const $source = $('#mod_form_source'); - - if ($type.val() === modForm.TYPE_SERVER_SIDE) { - $source.prop('disabled', false); - } else { - $source.val(modForm.SOURCE_STEAM_WORKSHOP); - $source.prop('disabled', true); - modForm.onModSourceChange(); - } -}; - modForm.onModSourceChange = () => { const $source = $('#mod_form_source'); const $url = $('#mod_form_url'); const $directory = $('#mod_form_directory'); - - $url.closest('.form-group').toggleClass('d-none', $source.val() !== modForm.SOURCE_STEAM_WORKSHOP); - $directory.closest('.form-group').toggleClass('d-none', $source.val() !== modForm.SOURCE_DIRECTORY); + const $type = $('#mod_form_type'); if ($source.val() === modForm.SOURCE_STEAM_WORKSHOP) { $directory.val(''); + $type.prop('selectedIndex', 0); } else if ($source.val() === modForm.SOURCE_DIRECTORY) { $url.val(''); + $type.val(modForm.TYPE_SERVER_SIDE); } + + $url.closest('.form-group').toggleClass('d-none', $source.val() !== modForm.SOURCE_STEAM_WORKSHOP); + $type.prop('disabled', $source.val() !== modForm.SOURCE_STEAM_WORKSHOP); + $directory.closest('.form-group').toggleClass('d-none', $source.val() !== modForm.SOURCE_DIRECTORY); }; $(() => { - modForm.onModTypeChange(); - $('#mod_form_type').on('change', (e) => { - modForm.onModTypeChange(); - }); - modForm.onModSourceChange(); - $('#mod_form_source').on('change', (e) => { + $('#mod_form_source').on('change', () => { modForm.onModSourceChange(); }); });