Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warning when username starts with a lowercase letter #194

Merged
merged 4 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
mrsrec marked this conversation as resolved.
Show resolved Hide resolved
],
"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.parentElement.parentElement.parentElement.parentElement);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to use .closest instead of this? This seems janky and likely to break with some OOUI update.

// Start with username input field, and go up 4 levels, 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();
Kenny2github marked this conversation as resolved.
Show resolved Hide resolved
// 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
mrsrec marked this conversation as resolved.
Show resolved Hide resolved
],

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