* breaking: remove `submitter` option from experimental form `validate()` method, always provide default submitter
* fix
* remove log
---------
Co-authored-by: Tee Ming <chewteeming01@gmail.com>
--- /dev/null
+---
+'@sveltejs/kit': patch
+---
+
+breaking: remove `submitter` option from experimental form `validate()` method, always provide default submitter
includeUntouched?: boolean;
/** Set this to `true` to only run the `preflight` validation. */
preflightOnly?: boolean;
- /** Perform validation as if the form was submitted by the given button. */
- submitter?: HTMLButtonElement | HTMLInputElement;
}): Promise<void>;
/** The result of the form submission */
get result(): Output | undefined;
},
validate: {
/** @type {RemoteForm<any, any>['validate']} */
- value: async ({ includeUntouched = false, preflightOnly = false, submitter } = {}) => {
+ value: async ({ includeUntouched = false, preflightOnly = false } = {}) => {
if (!element) return;
const id = ++validate_id;
// wait a tick in case the user is calling validate() right after set() which takes time to propagate
await tick();
- const form_data = new FormData(element, submitter);
+ const default_submitter = /** @type {HTMLElement | undefined} */ (
+ element.querySelector('button:not([type]), [type="submit"]')
+ );
+
+ const form_data = new FormData(element, default_submitter);
/** @type {InternalRemoteFormIssue[]} */
let array = [];
const schema = v.object({
foo: v.picklist(['a', 'b', 'c']),
bar: v.picklist(['d', 'e']),
- button: v.optional(v.literal('submitter'))
+ button: v.literal('submitter')
});
- let submitter;
+
let error = $state(false);
</script>
<input {...my_form.fields.bar.as('text')} />
- <button>submit (imperative validation)</button>
+ <button {...my_form.fields.button.as('submit', 'incorrect_value')}> submit </button>
- <button bind:this={submitter} {...my_form.fields.button.as('submit', 'incorrect_value')}>
- submit
- </button>
{#each my_form.fields.button.issues() as issue}
<p>{issue.message}</p>
{/each}
-</form>
-<button
- id="trigger-validate"
- onclick={() => my_form.validate({ includeUntouched: true, submitter })}
->
+ <button {...my_form.fields.button.as('submit', 'submitter')}>
+ submit (imperative validation)
+ </button>
+</form>
+<button id="trigger-validate" onclick={() => my_form.validate({ includeUntouched: true })}>
trigger validation
</button>
v.object({
foo: v.picklist(['a', 'b', 'c']),
bar: v.picklist(['d', 'e', 'f']),
- button: v.optional(v.literal('submitter'))
+ button: v.literal('submitter')
}),
async (data, issue) => {
// Test imperative validation
includeUntouched?: boolean;
/** Set this to `true` to only run the `preflight` validation. */
preflightOnly?: boolean;
- /** Perform validation as if the form was submitted by the given button. */
- submitter?: HTMLButtonElement | HTMLInputElement;
}): Promise<void>;
/** The result of the form submission */
get result(): Output | undefined;