Common.js: Difference between revisions
From MiniPC.club
Philo3lancer (talk | contribs) Created page with "→Any JavaScript here will be loaded for all users on every page load.: $(document).ready(function() { if (mw.config.get('wgPageName') === 'Special:FormEdit') { window.location = '/wiki/Special:FormEdit/Mini-PC/_'; } });" |
Philo3lancer (talk | contribs) No edit summary Tag: Manual revert |
||
(5 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
$(document).ready(function() { | $(document).ready(function() { | ||
if (mw.config.get('wgPageName') === 'Special:FormEdit') { | if (mw.config.get('wgPageName') === 'Special:FormEdit') { | ||
window.location = ' | window.location = 'Special:FormEdit/Mini-PC/_'; | ||
} | } | ||
}); | }); | ||
$(document).ready(function() { | |||
$('form').submit(function(event) { | |||
let isValid = true; | |||
let errorMessage = ''; | |||
// Checking the required fields | |||
if ($('#Field_Brand').val() === '') { | |||
isValid = false; | |||
errorMessage += 'Please fill out the Brand field.\n'; | |||
} | |||
if ($('#Field_Model').val() === '') { | |||
isValid = false; | |||
errorMessage += 'Please fill out the Model field.\n'; | |||
} | |||
if ($('#Field_CPU_Model').val() === '') { | |||
isValid = false; | |||
errorMessage += 'Please fill out the CPU Model field.\n'; | |||
} | |||
// If it is not valid, we show an error message and prevent the form from being submitted. | |||
if (!isValid) { | |||
alert(errorMessage); | |||
event.preventDefault(); | |||
} | |||
}); | |||
}); |
Latest revision as of 21:08, 18 April 2025
/* Any JavaScript here will be loaded for all users on every page load. */ $(document).ready(function() { if (mw.config.get('wgPageName') === 'Special:FormEdit') { window.location = 'Special:FormEdit/Mini-PC/_'; } }); $(document).ready(function() { $('form').submit(function(event) { let isValid = true; let errorMessage = ''; // Checking the required fields if ($('#Field_Brand').val() === '') { isValid = false; errorMessage += 'Please fill out the Brand field.\n'; } if ($('#Field_Model').val() === '') { isValid = false; errorMessage += 'Please fill out the Model field.\n'; } if ($('#Field_CPU_Model').val() === '') { isValid = false; errorMessage += 'Please fill out the CPU Model field.\n'; } // If it is not valid, we show an error message and prevent the form from being submitted. if (!isValid) { alert(errorMessage); event.preventDefault(); } }); });