Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
compendium-v2
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
geant-swd
compendium-v2
Commits
acf7a622
Commit
acf7a622
authored
7 months ago
by
Bjarke Madsen
Browse files
Options
Downloads
Patches
Plain Diff
Override data protection contact validation in new validation function
parent
aff8006e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
compendium-frontend/src/survey/SurveyContainerComponent.tsx
+42
-13
42 additions, 13 deletions
compendium-frontend/src/survey/SurveyContainerComponent.tsx
compendium-frontend/src/survey/validation/validation.ts
+21
-0
21 additions, 0 deletions
compendium-frontend/src/survey/validation/validation.ts
with
63 additions
and
13 deletions
compendium-frontend/src/survey/SurveyContainerComponent.tsx
+
42
−
13
View file @
acf7a622
...
@@ -11,27 +11,56 @@ import "survey-core/modern.min.css";
...
@@ -11,27 +11,56 @@ import "survey-core/modern.min.css";
import
'
./survey.scss
'
;
import
'
./survey.scss
'
;
import
useMatomo
from
"
../matomo/UseMatomo
"
;
import
useMatomo
from
"
../matomo/UseMatomo
"
;
import
{
FunctionFactory
}
from
"
survey-core
"
;
import
{
FunctionFactory
}
from
"
survey-core
"
;
import
{
validationFunctions
}
from
"
./validation/validation
"
;
function
validateWebsiteUrl
(
params
)
{
const
value
=
params
[
0
];
const
nonEmpty
=
params
[
1
]
||
false
;
if
(
!
nonEmpty
&&
(
value
===
undefined
||
value
==
null
))
{
interface
ValidationQuestion
{
return
true
;
name
?:
string
;
}
value
?:
any
;
data
?:
ValidationQuestion
;
}
// Overrides for questions that need to be validated differently from the default expression in their group
const
questionOverrides
=
{
data_protection_contact
:
(...
args
)
=>
true
,
// don't validate the contact field, anything goes..
}
function
validateQuestion
(
this
:
{
question
:
ValidationQuestion
,
row
?:
any
},
params
:
any
)
{
try
{
try
{
if
(
value
.
includes
(
"
"
))
{
const
question
=
this
.
question
;
return
false
;
const
validator
=
params
[
0
]
||
undefined
;
const
matrix
=
question
.
data
&&
'
name
'
in
question
.
data
;
let
questionName
;
if
(
matrix
)
{
questionName
=
question
.
data
!
.
name
;
}
else
{
questionName
=
question
.
name
;
}
const
value
=
question
.
value
const
hasOverride
=
questionOverrides
[
questionName
];
if
(
hasOverride
)
{
return
hasOverride
(
value
,
...
params
.
slice
(
1
));
}
}
const
url
=
new
URL
(
value
);
const
validationFunction
=
validationFunctions
[
validator
];
return
!!
url
if
(
!
validationFunction
)
{
}
catch
(
err
)
{
throw
new
Error
(
`Validation function
${
validator
}
not found for question
${
questionName
}
`
);
}
return
validationFunction
(
value
,
...
params
.
slice
(
1
));
}
catch
(
e
)
{
console
.
error
(
e
);
return
false
;
return
false
;
}
}
}
}
Serializer
.
addProperty
(
"
itemvalue
"
,
"
customDescription:text
"
);
Serializer
.
addProperty
(
"
itemvalue
"
,
"
customDescription:text
"
);
Serializer
.
addProperty
(
"
question
"
,
"
hideCheckboxLabels:boolean
"
);
Serializer
.
addProperty
(
"
question
"
,
"
hideCheckboxLabels:boolean
"
);
...
@@ -41,8 +70,8 @@ function SurveyContainerComponent({ loadFrom }) {
...
@@ -41,8 +70,8 @@ function SurveyContainerComponent({ loadFrom }) {
const
{
year
,
nren
}
=
useParams
();
// nren stays empty for inspect and try
const
{
year
,
nren
}
=
useParams
();
// nren stays empty for inspect and try
const
[
error
,
setError
]
=
useState
<
string
>
(
'
loading survey...
'
);
const
[
error
,
setError
]
=
useState
<
string
>
(
'
loading survey...
'
);
if
(
!
FunctionFactory
.
Instance
.
hasFunction
(
"
validate
WebsiteUrl
"
))
{
if
(
!
FunctionFactory
.
Instance
.
hasFunction
(
"
validate
Question
"
))
{
FunctionFactory
.
Instance
.
register
(
"
validate
WebsiteUrl
"
,
validate
WebsiteUrl
);
FunctionFactory
.
Instance
.
register
(
"
validate
Question
"
,
validate
Question
);
}
}
const
{
trackPageView
}
=
useMatomo
();
const
{
trackPageView
}
=
useMatomo
();
...
...
This diff is collapsed.
Click to expand it.
compendium-frontend/src/survey/validation/validation.ts
0 → 100644
+
21
−
0
View file @
acf7a622
function
validateWebsiteUrl
(
value
,
nonEmpty
=
false
)
{
if
(
!
nonEmpty
&&
(
value
===
undefined
||
value
==
null
))
{
return
true
;
}
try
{
value
=
value
.
trim
();
if
(
value
.
includes
(
"
"
))
{
return
false
;
}
const
url
=
new
URL
(
value
);
return
!!
url
}
catch
(
err
)
{
return
false
;
}
}
export
const
validationFunctions
=
{
validateWebsiteUrl
,
}
\ No newline at end of file
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