Skip to content

Commit

Permalink
Add warning when username starts with a lowercase letter (#194)
Browse files Browse the repository at this point in the history
* add username warning

Warning for people who select a username starting with a lowercase letter

* Update main.js

* add comma from Kenny2github

Co-authored-by: AbyxDev <ken@abyx.dev>

* Update main.js

---------

Co-authored-by: AbyxDev <ken@abyx.dev>
  • Loading branch information
mrsrec and Kenny2github authored Mar 14, 2024
1 parent 77a7cb5 commit c7f995e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
3 changes: 2 additions & 1 deletion extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@
],
"localBasePath": "resources",
"messages": [
"scratch-confirmaccount-click-copy-alert"
"scratch-confirmaccount-click-copy-alert",
"createacct-normalization"
],
"dependencies": [
"mediawiki.util",
Expand Down
20 changes: 19 additions & 1 deletion resources/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ $(function () {
if (!elem) return;
elem.onclick = function() {
copyToClipboard(document.getElementById("mw-scratch-confirmaccount-verifcode"));
mw.notify( mw.message( 'scratch-confirmaccount-click-copy-alert', { autoHide: true }, {autoHideSeconds: 5}) ); // Use an i18n message to send a notification
}
});

Expand All @@ -48,6 +49,23 @@ function copyToClipboard(temptext) {
tempItem.focus();
tempItem.select();
document.execCommand('copy');
mw.notify( mw.message( 'scratch-confirmaccount-click-copy-alert', { autoHide: true }, {autoHideSeconds: 5}) ); // Use an i18n message to send a notification
tempItem.parentElement.removeChild(tempItem);
}


$(function () {
const elem = document.getElementsByName("scratchusername")[0];
if (!elem) return;

elem.onblur = function() {
var currentname = elem.value || "";
var usernameblock = new OO.ui.infuse(elem.closest('.oo-ui-layout'));
// Start with username input field, and go to the entire username container that OOUI will infuse onto
var noticebox = [];
if(currentname.length > 0 && currentname[0].match("[a-z]")){// Compare first letter to a regex, to check if it starts with a lowercase letter
noticebox[0] = new mw.message("createacct-normalization", "", currentname[0].toUpperCase() + currentname.slice(1)).text();
// If it'd change, add a notice with the first letter captialized
}
usernameblock.setNotices(noticebox);// Save out any notices (importantly, this will *remove* a notice if it no longer applies)
}
});
6 changes: 4 additions & 2 deletions src/SpecialRequestAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,14 @@ function usernameAndVerificationArea() {
new OOUI\TextInputWidget( [
'name' => 'scratchusername',
'required' => true,
'value' => $request->getText('scratchusername')
'value' => $request->getText('scratchusername'),
] ),
[
'label' => wfMessage('scratch-confirmaccount-scratchusername')->text(),
'align' => 'top',
]
'infusable' => true,
],

),
new OOUI\FieldLayout(
new OOUI\TextInputWidget( [
Expand Down

0 comments on commit c7f995e

Please sign in to comment.