mirror of
https://github.com/danbulant/Portfolio
synced 2026-07-04 10:30:50 +00:00
fix: personalId validation
This commit is contained in:
parent
911a5f6ee2
commit
915708f2e8
1 changed files with 32 additions and 25 deletions
|
|
@ -49,6 +49,7 @@
|
||||||
let componentErrors = writable( {
|
let componentErrors = writable( {
|
||||||
candidate: {
|
candidate: {
|
||||||
telephone: false,
|
telephone: false,
|
||||||
|
personalIdMatch: false,
|
||||||
},
|
},
|
||||||
parents: [
|
parents: [
|
||||||
{
|
{
|
||||||
|
|
@ -59,7 +60,7 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
let personalIdBirthdateMatch = true;
|
|
||||||
const formInitialValues = {
|
const formInitialValues = {
|
||||||
gdpr: false,
|
gdpr: false,
|
||||||
personalIdOk: false,
|
personalIdOk: false,
|
||||||
|
|
@ -215,32 +216,32 @@
|
||||||
personalIdModal: false,
|
personalIdModal: false,
|
||||||
linkErrorModal: false
|
linkErrorModal: false
|
||||||
};
|
};
|
||||||
|
const validatePersonalId = () => {
|
||||||
|
if ($form.candidate.citizenship === 'Česká republika') {
|
||||||
|
if (
|
||||||
|
!isPersonalIdNumberWithBirthdateValid(
|
||||||
|
$form.candidate.personalIdNumber,
|
||||||
|
$form.candidate.birthdate
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
toast.push('Rodné číslo neodpovídá oficiální specifikaci či datumu narození', {
|
||||||
|
theme: {
|
||||||
|
'--toastColor': 'mintcream',
|
||||||
|
'--toastBackground': '#b91c1c',
|
||||||
|
'--toastBarBackground': '#7f1d1d'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$componentErrors['candidate']['personalIdMatch'] = true;
|
||||||
|
throw new Error('Rodné číslo neodpovídá datumu narození');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$componentErrors['candidate']['personalIdMatch'] = false;
|
||||||
|
}
|
||||||
|
|
||||||
const onSubmit = async (values: CandidateData) => {
|
const onSubmit = async (values: CandidateData) => {
|
||||||
console.log("submit button clicked");
|
console.log("submit button clicked");
|
||||||
console.log(pagesFilled.map((_, i) => !isPageInvalid(i)));
|
console.log(pagesFilled.map((_, i) => !isPageInvalid(i)));
|
||||||
|
|
||||||
if (pageIndex === 3) {
|
|
||||||
if (values.candidate.citizenship === 'Česká republika') {
|
|
||||||
if (
|
|
||||||
!isPersonalIdNumberWithBirthdateValid(
|
|
||||||
values.candidate.personalIdNumber,
|
|
||||||
values.candidate.birthdate
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
toast.push('Rodné číslo neodpovídá oficiální specifikaci či datumu narození', {
|
|
||||||
theme: {
|
|
||||||
'--toastColor': 'mintcream',
|
|
||||||
'--toastBackground': '#b91c1c',
|
|
||||||
'--toastBarBackground': '#7f1d1d'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
personalIdBirthdateMatch = false;
|
|
||||||
throw new Error('Rodné číslo neodpovídá datumu narození');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
personalIdBirthdateMatch = true;
|
|
||||||
}
|
|
||||||
if (pageIndex === pageCount) {
|
if (pageIndex === pageCount) {
|
||||||
console.log('submitting');
|
console.log('submitting');
|
||||||
// clone values to oldValues
|
// clone values to oldValues
|
||||||
|
|
@ -340,7 +341,7 @@
|
||||||
$typedErrors['candidate']['birthplace'] ||
|
$typedErrors['candidate']['birthplace'] ||
|
||||||
$typedErrors['candidate']['personalIdNumber'] ||
|
$typedErrors['candidate']['personalIdNumber'] ||
|
||||||
$typedErrors['candidate']['testLanguage'] ||
|
$typedErrors['candidate']['testLanguage'] ||
|
||||||
!personalIdBirthdateMatch
|
$componentErrors['candidate']['personalIdMatch']
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -759,11 +760,14 @@
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<Submit
|
<Submit
|
||||||
on:click={async (e) => {
|
on:click={async (e) => {
|
||||||
|
if (pageIndex === 4) {
|
||||||
|
console.log('validating personal id');
|
||||||
|
validatePersonalId();
|
||||||
|
}
|
||||||
await handleSubmit(e);
|
await handleSubmit(e);
|
||||||
console.log(pagesFilled.map((_, i) => !isPageInvalid(i)));
|
console.log(pagesFilled.map((_, i) => !isPageInvalid(i)));
|
||||||
if (isPageInvalid(pageIndex)) return;
|
if (isPageInvalid(pageIndex)) return;
|
||||||
if (pageIndex === pageCount) {
|
if (pageIndex !== pageCount) {
|
||||||
} else {
|
|
||||||
pagesFilled[pageIndex] = true;
|
pagesFilled[pageIndex] = true;
|
||||||
pageIndex++;
|
pageIndex++;
|
||||||
}
|
}
|
||||||
|
|
@ -779,6 +783,9 @@
|
||||||
<button
|
<button
|
||||||
class:dotActive={i === pageIndex}
|
class:dotActive={i === pageIndex}
|
||||||
on:click={async (e) => {
|
on:click={async (e) => {
|
||||||
|
if (pageIndex === 4 && i > pageIndex) {
|
||||||
|
validatePersonalId();
|
||||||
|
}
|
||||||
pageIndex -= pageIndex === pageCount ? 1 : 0;
|
pageIndex -= pageIndex === pageCount ? 1 : 0;
|
||||||
await handleSubmit(e);
|
await handleSubmit(e);
|
||||||
pagesFilled = pagesFilled.map((_, i) => !isPageInvalid(i));
|
pagesFilled = pagesFilled.map((_, i) => !isPageInvalid(i));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue