Skip to content

Remote functions Forms optional fields are always included in request #14695

@jere2101

Description

@jere2101

Describe the bug

In my repo i have input field that is optional and when it's filled it has to be an json object with a specific structure ( in my case an array with coordinates ).
I've the following validation in my schema:

{
...
bounds: v.optional(v.pipe(v.string(), transformJson, boundsSchema))
...
}

transformJson = v.transform((input: string) => {
	try {
		return JSON.parse(input);
	} catch {
		return {};
	}
});

const boundsSchema = v.array(v.tuple([v.number(), v.number()]));

My Problem is that an empty Input Text field is included as an empty string in the request to the remote function.

I don't know if this is the default behavior from now on and i have to bypass this with some conditional validation or if this is just a bug with the transformation from the form data to an object.

Thanks for your help

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-21ek1ezc?file=src%2Froutes%2F%2Bpage.svelte

The empty string can be seen when just submitting without inputting anything
Request Data:

Image

Response:
Image

Logs

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 20.19.1 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.8.2 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @sveltejs/adapter-auto: ^6.0.0 => 6.1.0 
    @sveltejs/kit: 2.46.4 => 2.46.4 
    @sveltejs/vite-plugin-svelte: ^6.0.0 => 6.2.0 
    svelte: ^5.39.11 => 5.39.11 
    vite: ^7.0.4 => 7.1.5

Severity

annoyance

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions