Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/polite-planes-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

chore: allow to run preflight validation only
3 changes: 3 additions & 0 deletions packages/kit/src/exports/public.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2021,7 +2021,10 @@ export type RemoteForm<Input extends RemoteFormInput | void, Output> = {
preflight(schema: StandardSchemaV1<Input, any>): RemoteForm<Input, Output>;
/** Validate the form contents programmatically */
validate(options?: {
/** Set this to `true` to also show validation issues of fields that haven't been touched yet. */
includeUntouched?: boolean;
/** Set this to `true` to only run the `preflight` validation. */
clientOnly?: boolean;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this, so it's explicitly linked to .preflight(...)?

Suggested change
clientOnly?: boolean;
preflightOnly?: boolean;

/** Perform validation as if the form was submitted by the given button. */
submitter?: HTMLButtonElement | HTMLInputElement;
}): Promise<void>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ export function form(id) {
},
validate: {
/** @type {RemoteForm<any, any>['validate']} */
value: async ({ includeUntouched = false, submitter } = {}) => {
value: async ({ includeUntouched = false, clientOnly = false, submitter } = {}) => {
if (!element) return;

const id = ++validate_id;
Expand All @@ -593,7 +593,7 @@ export function form(id) {

if (validated?.issues) {
array = validated.issues;
} else {
} else if (!clientOnly) {
form_data.set('sveltekit:validate_only', 'true');

const response = await fetch(`${base}/${app_dir}/remote/${action_id}`, {
Expand Down
3 changes: 3 additions & 0 deletions packages/kit/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1997,7 +1997,10 @@ declare module '@sveltejs/kit' {
preflight(schema: StandardSchemaV1<Input, any>): RemoteForm<Input, Output>;
/** Validate the form contents programmatically */
validate(options?: {
/** Set this to `true` to also show validation issues of fields that haven't been touched yet. */
includeUntouched?: boolean;
/** Set this to `true` to only run the `preflight` validation. */
clientOnly?: boolean;
/** Perform validation as if the form was submitted by the given button. */
submitter?: HTMLButtonElement | HTMLInputElement;
}): Promise<void>;
Expand Down
Loading