Skip to content

Commit 8b2b33b

Browse files
committed
Fix form send empty string instead of null
1 parent f0a6325 commit 8b2b33b

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

‎src/components/forms/databaseSearch.svelte‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
async function submit() {
99
const url = new URL(window.location.href);
10-
if (text.length > 0) {
10+
if (text) {
1111
url.searchParams.set("text", text);
1212
} else {
1313
url.searchParams.delete("text");

‎src/components/forms/elements/input.svelte‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,17 @@
2525
2626
uid += 1;
2727
const id = "input" + uid;
28+
29+
// An emptied input means null
30+
function normalize(input: string | number | null) {
31+
value = input === "" ? null : input;
32+
}
2833
</script>
2934

3035
<InputWrapper {error} for={id} {label} {required}>
3136
{#if type == "number"}
32-
<input bind:value type="number" {required} {...rest} {id} />
37+
<input bind:value={() => value ?? "", normalize} type="number" {required} {...rest} {id} />
3338
{:else}
34-
<input bind:value {type} {...rest} {id} />
39+
<input bind:value={() => value ?? "", normalize} {type} {...rest} {id} />
3540
{/if}
3641
</InputWrapper>

0 commit comments

Comments
 (0)