Skip to content

Commit 1cf0578

Browse files
author
Sebastian Flick
committed
navigate on submit
reloading still missing
1 parent bd552c6 commit 1cf0578

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

src/lib/components/VerseSelector.svelte

+23-21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<script>
22
import { goto } from '$app/navigation';
33
4+
export let targetPath = '/einzelverssynopse';
5+
46
/**
57
* @type {HTMLInputElement}
68
*/
@@ -12,37 +14,37 @@
1214
1315
let additional = '';
1416
15-
let valid = false;
17+
/**
18+
* @param {Event & { target: HTMLInputElement }} e
19+
*/
20+
function handleInput(e) {
21+
validateMinMax(e.target);
22+
}
1623
17-
const validateMinMax = (e) => {
18-
console.log(e);
19-
console.log(e.target.value);
20-
console.log(isNaN(e.target.value));
24+
const validateMinMax = (/** @type {HTMLInputElement } */ i) => {
2125
//validate if input is a Number
22-
if (isNaN(e.target.value) || e.target.value === '') {
23-
e.target.classList.add('input-error');
26+
if (isNaN(Number(i.value)) || i.value === '') {
27+
i.classList.add('input-error');
28+
return false;
2429
} else {
2530
//validate if input is within min and max
26-
if (
27-
parseInt(e.target.value) < parseInt(e.target.min) ||
28-
parseInt(e.target.value) > parseInt(e.target.max)
29-
) {
30-
console.log(e.target.value);
31-
console.log(e.target.min);
32-
console.log(e.target.max);
33-
34-
e.target.classList.add('input-error');
31+
if (parseInt(i.value) < parseInt(i.min) || parseInt(i.value) > parseInt(i.max)) {
32+
i.classList.add('input-error');
33+
return false;
3534
} else {
36-
e.target.classList.remove('input-error');
35+
i.classList.remove('input-error');
36+
return true;
3737
}
3838
}
3939
};
4040
</script>
4141

4242
<form
4343
class="flex max-w-full items-baseline gap-1 my-3"
44-
on:submit={(e) => {
45-
goto(`/einzelverssynopse/${thirties.value}/${verse.value}-${additional}`);
44+
on:submit|preventDefault={(e) => {
45+
if (validateMinMax(thirties) && validateMinMax(verse)) {
46+
goto(`${targetPath}/${thirties.value}/${verse.value}${additional ? '-' + additional : ''}`);
47+
}
4648
}}
4749
>
4850
<p>Vers:</p>
@@ -52,15 +54,15 @@
5254
class="input inline max-w-28"
5355
min="1"
5456
max="827"
55-
on:input={(e) => validateMinMax(e)}
57+
on:input={handleInput}
5658
bind:this={thirties}
5759
/>.<input
5860
type="number"
5961
placeholder="Vers"
6062
class="input max-w-20"
6163
min="1"
6264
max="30"
63-
on:input={(e) => validateMinMax(e)}
65+
on:input={handleInput}
6466
bind:this={verse}
6567
/>-<input type="text" placeholder="Zusatz" class="input max-w-20" bind:value={additional} />
6668
<button class="btn-icon variant-filled btn-icon-sm flex-shrink-0 flex-grow-0">

src/routes/einzelverssynopse/[dreissiger]/[vers]/+page.svelte

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,6 @@
7171
>Fassungsverse ein-/ausblenden und nach diesen sortieren</SlideToggle
7272
>
7373
<h2 class="h2 my-7">Zu Vers springen:</h2>
74-
<VerseSelector />
74+
<VerseSelector targetPath="/einzelverssynopse" />
7575
</section>
7676
</div>

0 commit comments

Comments
 (0)