Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
scratch-www
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
scratch-www
Commits
aa69de39
Commit
aa69de39
authored
Aug 12, 2019
by
Ben Wheeler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
keep showing validation errors on focus, until first keystroke; prioritize vulgarity
parent
d5a86a99
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
10 deletions
+26
-10
src/components/join-flow/username-step.jsx
src/components/join-flow/username-step.jsx
+26
-10
No files found.
src/components/join-flow/username-step.jsx
View file @
aa69de39
...
...
@@ -36,16 +36,22 @@ class UsernameStep extends React.Component {
// we allow username to be empty on blur, since you might not have typed anything yet
validateUsernameIfPresent
(
username
)
{
if
(
!
username
)
return
null
;
// skip validation if username is blank; null indicates valid
// if username is not blank, run both local and remote validations
const
localResult
=
validate
.
validateUsernameLocally
(
username
);
if
(
localResult
.
valid
)
{
return
validate
.
validateUsernameRemotely
(
username
).
then
(
remoteResult
=>
{
if
(
remoteResult
.
valid
)
return
null
;
return
validate
.
validateUsernameRemotely
(
username
).
then
(
remoteResult
=>
{
// there may be multiple validation errors. Prioritize vulgarity, then
// length, then having invalid chars, then all other remote reports
if
(
remoteResult
.
valid
===
false
&&
remoteResult
.
errMsgId
===
'
registration.validationUsernameVulgar
'
)
{
return
this
.
props
.
intl
.
formatMessage
({
id
:
remoteResult
.
errMsgId
});
}
else
if
(
localResult
.
valid
===
false
)
{
return
this
.
props
.
intl
.
formatMessage
({
id
:
localResult
.
errMsgId
});
}
else
if
(
remoteResult
.
valid
===
false
)
{
return
this
.
props
.
intl
.
formatMessage
({
id
:
remoteResult
.
errMsgId
});
}
)
;
}
return
this
.
props
.
intl
.
formatMessage
({
id
:
localResult
.
errMsgId
}
);
return
null
;
}
);
}
validatePasswordIfPresent
(
password
,
username
)
{
if
(
!
password
)
return
null
;
// skip validation if password is blank; null indicates valid
...
...
@@ -103,6 +109,7 @@ class UsernameStep extends React.Component {
handleSubmit
,
isSubmitting
,
setFieldError
,
setFieldValue
,
validateField
,
values
}
=
props
;
...
...
@@ -130,7 +137,10 @@ class UsernameStep extends React.Component {
validationClassName=
"validation-full-width-input"
/* eslint-disable react/jsx-no-bind */
onBlur=
{
()
=>
validateField
(
'
username
'
)
}
onFocus=
{
()
=>
setFieldError
(
'
username
'
,
null
)
}
onChange=
{
e
=>
{
setFieldValue
(
'
username
'
,
e
.
target
.
value
);
setFieldError
(
'
username
'
,
null
);
}
}
/* eslint-enable react/jsx-no-bind */
/>
<
div
className=
"join-flow-password-section"
>
...
...
@@ -149,7 +159,10 @@ class UsernameStep extends React.Component {
validate=
{
password
=>
this
.
validatePasswordIfPresent
(
password
,
values
.
username
)
}
validationClassName=
"validation-full-width-input"
onBlur=
{
()
=>
validateField
(
'
password
'
)
}
onFocus=
{
()
=>
setFieldError
(
'
password
'
,
null
)
}
onChange=
{
e
=>
{
setFieldValue
(
'
password
'
,
e
.
target
.
value
);
setFieldError
(
'
password
'
,
null
);
}
}
/* eslint-enable react/jsx-no-bind */
/>
<
FormikInput
...
...
@@ -169,7 +182,10 @@ class UsernameStep extends React.Component {
onBlur=
{
()
=>
validateField
(
'
passwordConfirm
'
)
}
onFocus=
{
()
=>
setFieldError
(
'
passwordConfirm
'
,
null
)
}
onChange=
{
e
=>
{
setFieldValue
(
'
passwordConfirm
'
,
e
.
target
.
value
);
setFieldError
(
'
passwordConfirm
'
,
null
);
}
}
/* eslint-enable react/jsx-no-bind */
/>
<
div
className=
"join-flow-input-title"
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment