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
Harbor Registry
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
simmctic
form-creator
form-creator-ui
Commits
606d8a1d
Commit
606d8a1d
authored
4 years ago
by
Stephanie Briere Americo
Browse files
Options
Downloads
Plain Diff
Merge branch 'issue/28' into 'development'
Issue
#28
: Fix mouse being pushed in /create and /edit See merge request
!30
parents
fc92fe85
ce67dc0f
No related branches found
No related tags found
3 merge requests
!58
Version 1.1
,
!54
Issue #53: Fix password info
,
!30
Issue #28: Fix mouse being pushed in /create and /edit
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/components/fieldsDisplayForm/utils/schemas.js
+20
-49
20 additions, 49 deletions
src/components/fieldsDisplayForm/utils/schemas.js
src/contexts/useForm.js
+4
-4
4 additions, 4 deletions
src/contexts/useForm.js
with
24 additions
and
53 deletions
src/components/fieldsDisplayForm/utils/schemas.js
+
20
−
49
View file @
606d8a1d
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
)
=>
{
/**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
;
});
}
/**
Schema to validate the description field from every form array object
. */
const
descriptionTextSchema
=
Yup
.
string
().
test
(
"
al
phabets
"
,
"
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
testQuestionTextSchema
(
error
,
value
)
{
v
al
ue
?
checkText
(
value
)
?
(
error
.
errorMsg
.
question
=
""
)
:
(
error
.
errorMsg
.
question
=
"
O caractere não é permitido
"
)
:
(
error
.
errorMsg
.
question
=
"
Este campo é obrigatório!
"
);
}
);
/** 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
()
...
...
This diff is collapsed.
Click to expand it.
src/contexts/useForm.js
+
4
−
4
View file @
606d8a1d
...
...
@@ -138,7 +138,7 @@ const useForm = () => {
*/
async
function
setQuestionField
(
value
,
index
)
{
form
[
index
].
question
=
value
;
await
testQuestionTextSchema
(
form
,
value
,
index
);
testQuestionTextSchema
(
form
[
index
].
error
,
value
);
setForm
([...
form
]);
}
...
...
@@ -148,7 +148,7 @@ const useForm = () => {
*/
async
function
setDescriptionField
(
value
,
index
)
{
form
[
index
].
description
=
value
;
await
testDescriptionTextSchema
(
form
,
value
,
index
);
testDescriptionTextSchema
(
form
[
index
].
error
,
value
);
setForm
([...
form
]);
}
...
...
@@ -157,9 +157,9 @@ const useForm = () => {
* @param index - the position on the array that the operation needs to be done;
* @param idopt - the id of the options being changed, inside the form[index].
*/
async
function
setSelectOption
(
value
,
index
,
idopt
)
{
function
setSelectOption
(
value
,
index
,
idopt
)
{
form
[
index
].
options
[
idopt
]
=
value
;
await
selectOptionTextTesting
(
form
,
value
,
index
,
idopt
);
selectOptionTextTesting
(
form
[
index
].
error
,
value
,
idopt
);
setForm
([...
form
]);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment