Skip to content

docs: Document the use of fields.allIssues() to check if remote form is valid - #16137

Closed
Kynson wants to merge 2 commits into
sveltejs:mainfrom
Kynson:main
Closed

Kynson wants to merge 2 commits into
sveltejs:mainfrom
Kynson:main

Conversation

@Kynson

@Kynson Kynson commented Jun 23, 2026 •

Copy link
Copy Markdown

closes #16032

As discussed in #16080, the documentation should document the pattern of negating fields.allIssues() for checking the validity of the form. This PR adds an example of using this pattern for disabling the submit button.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check (N/A)

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:. (N/A)

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

@changeset-bot

changeset-bot Bot commented Jun 23, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: de0d2a7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@teemingc teemingc added the documentation Improvements or additions to documentation label Jun 23, 2026
- Updated example of using allIssues() to check if the form is valid
@Rich-Harris

Copy link
Copy Markdown
Member

We shouldn't use this specific example, because it fails the progressive enhancement test. If you submitted this form with invalid data, and (because of whatever transient reason) JavaScript was unavailable, you wouldn't be able to resubmit it once you'd fixed the data — the button would be permanently disabled.

Do you have another real world use case that could be turned into an example? (I would try and suggest one, but I've never needed to use this pattern — if I'm using issues() or allIssues() it's to show the issues, and if I need to style something I can just target [aria-invalid="true"] which is automatically applied to invalid form controls.)

@Rich-Harris
Rich-Harris marked this pull request as draft June 24, 2026 02:57
@Kynson

Kynson commented Jun 24, 2026 •

Copy link
Copy Markdown
Author

@Rich-Harris Thanks for the review. Personally, I think this pattern is most useful for dynamically disabling and enabling the form submit button as an indication whether the form should be submitted.

If progressive enhancement is preferred, how about modifying one of the existing example:

<form {...createPost}>
	<!-- -->
</form>

{#if !createPost.fields.allIssues()}
	<div class="confirmation">
		<h1>Confirmation</h1>
		<h2>{createPost.fields.title.value()}</h2>
		<div>{@html render(createPost.fields.content.value())}</div>
	</div>
{/if}

This can act as a confirmation section even if JS is not available. Alternatively I can think of conditionally displaying the issue list when it contains other elements like a header which should hide if the form is valid (although the dobule negation is actually not necessary here as allIssues returns undefined when here is no issues):

<form {...createPost}>
	{#if !!createPost.fields.allIssues()}
		<div class="issues">
			<h1>Please resolve the following issues</h1>
			{#each createPost.fields.allIssues() as issue}
				<p>{issue.message}</p>
			{/each}
		</div>
	{/if}
</form>

The above two are the ones that I can think of, although not commonly used by me.
Feel free to suggest other examples, I am happy to modify my PR. I am sorry that the original one is not good enough.

@Rich-Harris

Copy link
Copy Markdown
Member

What if we didn't add any illustrative code at all but just spelled it out? #16186

@Kynson

Kynson commented Jun 27, 2026

Copy link
Copy Markdown
Author

Sure this will also do.

@teemingc

Copy link
Copy Markdown
Member

Closing in favour of #16186

@teemingc teemingc closed this Jun 30, 2026
teemingc added a commit that referenced this pull request Jun 30, 2026
alternative to #16137

---------

Co-authored-by: Tee Ming <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose an isValid Field for Remote Form

3 participants