mirror of
https://github.com/danbulant/Portfolio
synced 2026-06-09 17:52:14 +00:00
refactor: filled page
This commit is contained in:
parent
f947afb013
commit
23b0e3437a
1 changed files with 13 additions and 11 deletions
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
const pageCount = 5;
|
const pageCount = 5;
|
||||||
let pageIndex = 0;
|
let pageIndex = 0;
|
||||||
let pagesFilled = 0;
|
let pagesFilled = [false, false, false, false, false];
|
||||||
|
|
||||||
const formInitialValues = {
|
const formInitialValues = {
|
||||||
gdpr: false,
|
gdpr: false,
|
||||||
|
|
@ -438,7 +438,7 @@
|
||||||
if (isPageInvalid()) return;
|
if (isPageInvalid()) return;
|
||||||
if (pageIndex === pageCount) {
|
if (pageIndex === pageCount) {
|
||||||
} else {
|
} else {
|
||||||
pagesFilled++;
|
pagesFilled[pageIndex] = true;
|
||||||
pageIndex++;
|
pageIndex++;
|
||||||
}
|
}
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|
@ -453,15 +453,17 @@
|
||||||
<button
|
<button
|
||||||
class:dotActive={i === pageIndex}
|
class:dotActive={i === pageIndex}
|
||||||
on:click={async (e) => {
|
on:click={async (e) => {
|
||||||
if (i <= pagesFilled) {
|
const progress = pagesFilled.slice(0, i ).every((item) => item === true);
|
||||||
// never skip unfilled or invalid pages
|
if (progress) {
|
||||||
pageIndex = i;
|
if (i > pageIndex) {
|
||||||
} else if (i == pagesFilled + 1) {
|
// if next page is clicked, validate current page
|
||||||
// if next page is clicked, validate current page
|
await handleSubmit(e);
|
||||||
await handleSubmit(e);
|
if (isPageInvalid()) return;
|
||||||
if (isPageInvalid()) return;
|
pagesFilled[i] = true;
|
||||||
pagesFilled++;
|
pageIndex++;
|
||||||
pageIndex++;
|
} else {
|
||||||
|
pageIndex = i;
|
||||||
|
}
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
errors.set(formInitialValues);
|
errors.set(formInitialValues);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue