Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
form-creator-ui
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
simmctic
form-creator
form-creator-ui
Merge requests
!30
Issue
#28
: Fix mouse being pushed in /create and /edit
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Merged
Issue
#28
: Fix mouse being pushed in /create and /edit
issue/28
into
development
Overview
0
Commits
1
Pipelines
0
Changes
2
Merged
Issue #28: Fix mouse being pushed in /create and /edit
Gabriel Silva Hermida
requested to merge
issue/28
into
development
Sep 10, 2020
Overview
0
Commits
1
Pipelines
0
Changes
2
closes
#28 (closed)
Signed-off-by: Gabriel Silva Hermida
gash18@inf.ufpr.br
0
0
Merge request reports
Compare
development
development (base)
and
latest version
latest version
3e68ca6e
1 commit,
Sep 10, 2020
2 files
+
24
−
53
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
src/components/fieldsDisplayForm/utils/schemas.js
+
20
−
49
View file @ 3e68ca6e
Edit in single-file editor
Open in Web IDE
Show full file
import
*
as
Yup
from
"
yup
"
;
/** The validation through Yup is schema based, so there are schemas and it's validations. */
/** Schema to validate the question field from every form array object. */
const
questionTextSchema
=
Yup
.
string
()
.
required
(
"
Este campo é obrigatório!
"
)
.
test
(
"
alphabets
"
,
"
O caractere não é permitido
"
,
(
value
)
=>
{
return
/^
[
A-Za-z!?$%,. 1234567890àèìòùáéíóúâêîôûãõç
]
+$/
.
test
(
value
);
});
/**Function that compares the value with a regex, to assure the input is valid */
function
checkText
(
value
)
{
return
/^
[
A-Za-z!?$%,. 1234567890àèìòùáéíóúâêîôûãõç
]
+$/
.
test
(
value
);
}
/** Function that applies the validation of it's used schema and sets the error messages. */
export
async
function
testQuestionTextSchema
(
form
,
value
,
index
)
{
await
questionTextSchema
.
validate
(
value
)
.
then
((
x
)
=>
{
form
[
index
].
error
.
errorMsg
.
question
=
""
;
})
.
catch
((
err
)
=>
{
form
[
index
].
error
.
errorMsg
.
question
=
err
.
message
;
});
export
async
function
testQuestionTextSchema
(
error
,
value
)
{
value
?
checkText
(
value
)
?
(
error
.
errorMsg
.
question
=
""
)
:
(
error
.
errorMsg
.
question
=
"
O caractere não é permitido
"
)
:
(
error
.
errorMsg
.
question
=
"
Este campo é obrigatório!
"
);
}
/** Schema to validate the description field from every form array object. */
const
descriptionTextSchema
=
Yup
.
string
().
test
(
"
alphabets
"
,
"
O caractere não é permitido
"
,
(
value
)
=>
{
if
(
!
value
)
return
true
;
return
/^
[
A-Za-z!?$%,. 1234567890àèìòùáéíóúâêîôûãõ
\b
-
]
+$/
.
test
(
value
);
}
);
/** Function that applies the validation of it's used schema and sets the error messages. */
export
async
function
testDescriptionTextSchema
(
form
,
value
,
index
)
{
await
descriptionTextSchema
.
validate
(
value
)
.
then
((
x
)
=>
{
form
[
index
].
error
.
errorMsg
.
description
=
""
;
})
.
catch
((
err
)
=>
{
form
[
index
].
error
.
errorMsg
.
description
=
err
.
message
;
});
export
async
function
testDescriptionTextSchema
(
error
,
value
)
{
value
&&
checkText
(
value
)
?
(
error
.
errorMsg
.
description
=
""
)
:
(
error
.
errorMsg
.
description
=
"
O caractere não é permitido
"
);
}
/** Schema to validate the number of options at options field from FormFieldSelect, FormFieldCheckbox and FormFieldRadio. */
const
selectOptionsSchema
=
Yup
.
array
()
@@ -87,23 +68,13 @@ export async function testSubformSchema(form, index) {
form
[
index
].
error
.
errorMsg
.
subformUsage
=
err
.
message
;
});
}
/** Schema to validate the content of the options field from FormFieldSelect, FormFieldCheckbox and FormFieldRadio. */
const
optSchema
=
Yup
.
string
()
.
required
(
"
Por favor, preencha esta opção
"
)
.
test
(
"
alphabets
"
,
"
O caractere não é permitido
"
,
(
value
)
=>
{
if
(
!
value
)
return
true
;
return
/^
[
A-Za-z!?$%,. àèìòùáéíóúâêîôûãõ
\b
-
]
+$/
.
test
(
value
);
});
/** Function that applies the validation of it's used schema and sets the error messages. */
export
async
function
selectOptionTextTesting
(
form
,
value
,
index
,
idopt
)
{
await
optSchema
.
validate
(
value
)
.
then
((
x
)
=>
{
form
[
index
].
error
.
errorMsg
.
options
[
idopt
]
=
""
;
})
.
catch
((
err
)
=>
{
form
[
index
].
error
.
errorMsg
.
options
[
idopt
]
=
err
.
message
;
});
export
async
function
selectOptionTextTesting
(
error
,
value
,
idopt
)
{
value
?
checkText
(
value
)
?
(
error
.
errorMsg
.
options
[
idopt
]
=
""
)
:
(
error
.
errorMsg
.
options
[
idopt
]
=
"
O caractere não é permitido
"
)
:
(
error
.
errorMsg
.
options
[
idopt
]
=
"
Por favor, preencha esta opção
"
);
}
/** Schema to validate the quantity field of the validation from FormFieldText. */
const
textValidationSchema
=
Yup
.
string
()
Loading