Skip to content

Allow skipping use:enhance with data-sveltekit-reload #13180

Closed as not planned
Closed as not planned
@fehnomenal

Description

@fehnomenal

Describe the problem

I'm having a search form with multiple fields for various criteria. The table below the form displays the database results correctly filtered. If I click the search button the criteria are correctly updated and so is the result table.
The form is method="post" and use:enhance and the search button has formmethod="get". The reason is that the same form is also used for form actions (think along the lines of "do this for all filtered items"). And all of this works great so far.

Now I need to add a button to export the filtered items. While the fetching from the database takes longer than acceptable I do not want to start a background task, but start downloading the data as soon as it is ready. This works great with a server endpoint that returns a response with a ReadableStream and the button having formtarget="_blank" but only without JS or without progressive enhancement.
Right now it does a fetch request to the target url (overwritten on the export button) but fails at parsing the CSV data as json (JSON.parse: unexpected character at line 1 column 1 of the JSON data).

Describe the proposed solution

I would like to be able to skip the progressive enhancement with the data-sveltekit-reload attribute on either the form element or the form submit element.

Alternatives considered

One alternative would be to duplicate each field and sync them with javascript. The duplicate would then be assigned to the export form which would be not enhanced. This does not work w/o js.

Importance

would make my life easier

Additional Information

Putting these lines in handle_submit results in the expected behavior:

		const skip = event.submitter?.getAttribute('data-sveltekit-reload')
			?? form_element.getAttribute('data-sveltekit-reload');
		if (skip === 'true') return;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions