mirror of
https://github.com/danbulant/Portfolio
synced 2026-06-17 05:21:07 +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( {
|
||||
candidate: {
|
||||
telephone: false,
|
||||
personalIdMatch: false,
|
||||
},
|
||||
parents: [
|
||||
{
|
||||
|
|
@ -59,7 +60,7 @@
|
|||
}
|
||||
]
|
||||
});
|
||||
let personalIdBirthdateMatch = true;
|
||||
|
||||
const formInitialValues = {
|
||||
gdpr: false,
|
||||
personalIdOk: false,
|
||||
|
|
@ -215,32 +216,32 @@
|
|||
personalIdModal: 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) => {
|
||||
console.log("submit button clicked");
|
||||
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) {
|
||||
console.log('submitting');
|
||||
// clone values to oldValues
|
||||
|
|
@ -340,7 +341,7 @@
|
|||
$typedErrors['candidate']['birthplace'] ||
|
||||
$typedErrors['candidate']['personalIdNumber'] ||
|
||||
$typedErrors['candidate']['testLanguage'] ||
|
||||
!personalIdBirthdateMatch
|
||||
$componentErrors['candidate']['personalIdMatch']
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -759,11 +760,14 @@
|
|||
<div class="field">
|
||||
<Submit
|
||||
on:click={async (e) => {
|
||||
if (pageIndex === 4) {
|
||||
console.log('validating personal id');
|
||||
validatePersonalId();
|
||||
}
|
||||
await handleSubmit(e);
|
||||
console.log(pagesFilled.map((_, i) => !isPageInvalid(i)));
|
||||
if (isPageInvalid(pageIndex)) return;
|
||||
if (pageIndex === pageCount) {
|
||||
} else {
|
||||
if (pageIndex !== pageCount) {
|
||||
pagesFilled[pageIndex] = true;
|
||||
pageIndex++;
|
||||
}
|
||||
|
|
@ -779,6 +783,9 @@
|
|||
<button
|
||||
class:dotActive={i === pageIndex}
|
||||
on:click={async (e) => {
|
||||
if (pageIndex === 4 && i > pageIndex) {
|
||||
validatePersonalId();
|
||||
}
|
||||
pageIndex -= pageIndex === pageCount ? 1 : 0;
|
||||
await handleSubmit(e);
|
||||
pagesFilled = pagesFilled.map((_, i) => !isPageInvalid(i));
|
||||
|
|
|
|||
Loading…
Reference in a new issue