Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fehnomenal opened this issue Dec 16, 2024 · 0 comments
Open

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

fehnomenal opened this issue Dec 16, 2024 · 0 comments
Labels
feature / enhancement New feature or request

Comments

@fehnomenal
Copy link
Contributor

fehnomenal commented Dec 16, 2024

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;
@eltigerchino eltigerchino added the feature / enhancement New feature or request label Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature / enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants