fix(GenKeyModal): Add trim to username

Closes: #5134
This commit is contained in:
Boris Melnik 2022-03-25 17:35:36 +03:00
parent 5147c6febb
commit bc23762a05
1 changed files with 10 additions and 9 deletions

View File

@ -33,21 +33,22 @@ ModalPopup {
validationError: displayNameValidationError validationError: displayNameValidationError
maxLength: 24 maxLength: 24
onTextChanged: { onTextChanged: {
let trimmedText = displayNameInput.text.trim()
if(displayNameInput.text === ""){ if(displayNameInput.text === ""){
displayNameValidationError = qsTr("Display name is required") displayNameValidationError = qsTr("Display name is required")
} else if (!displayNameInput.text.match(/^[a-zA-Z0-9\- ]+$/)){ } else if (!trimmedText.match(/^[a-zA-Z0-9\- ]+$/)){
displayNameValidationError = qsTr("Only letters, numbers, underscores and hyphens allowed") displayNameValidationError = qsTr("Only letters, numbers, underscores and hyphens allowed")
} else if (displayNameInput.text.length > 24) { } else if (trimmedText.length > 24) {
displayNameValidationError = qsTr("24 character username limit") displayNameValidationError = qsTr("24 character username limit")
} else if (displayNameInput.text.length < 5) { } else if (trimmedText.length < 5) {
displayNameValidationError = qsTr("Username must be at least 5 characters") displayNameValidationError = qsTr("Username must be at least 5 characters")
} else if (displayNameInput.text.endsWith(".eth")) { } else if (trimmedText.endsWith(".eth")) {
displayNameValidationError = qsTr(`Usernames ending with ".eth" are not allowed`) displayNameValidationError = qsTr(`Usernames ending with ".eth" are not allowed`)
} else if (displayNameInput.text.endsWith("-eth")) { } else if (trimmedText.endsWith("-eth")) {
displayNameValidationError = qsTr(`Usernames ending with "-eth" are not allowed`) displayNameValidationError = qsTr(`Usernames ending with "-eth" are not allowed`)
} else if (displayNameInput.text.endsWith("_eth")) { } else if (trimmedText.endsWith("_eth")) {
displayNameValidationError = qsTr(`Usernames ending with "_eth" are not allowed`) displayNameValidationError = qsTr(`Usernames ending with "_eth" are not allowed`)
} else if (globalUtils.isAlias(displayNameInput.text)){ } else if (globalUtils.isAlias(trimmedText)){
displayNameValidationError = qsTr("Sorry, the name you have chosen is not allowed, try picking another username") displayNameValidationError = qsTr("Sorry, the name you have chosen is not allowed, try picking another username")
} else { } else {
displayNameValidationError = "" displayNameValidationError = ""
@ -76,7 +77,7 @@ ModalPopup {
footer: StatusRoundButton { footer: StatusRoundButton {
objectName: "submitButton" objectName: "submitButton"
id: submitBtn id: submitBtn
enabled: displayNameInput.text !== "" enabled: displayNameInput.text.trim() !== "" && displayNameInput.text.trim().length >= 5
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.topMargin: Style.current.padding anchors.topMargin: Style.current.padding
anchors.right: parent.right anchors.right: parent.right
@ -84,7 +85,7 @@ ModalPopup {
icon.width: 20 icon.width: 20
icon.height: 16 icon.height: 16
onClicked : { onClicked : {
onNextClick(selectedIndex, displayNameInput.text); onNextClick(selectedIndex, displayNameInput.text.trim());
popup.close() popup.close()
} }
} }