Repository navigation
Conversation
|
- Updated example of using allIssues() to check if the form is valid
|
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 |
|
@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. |
|
What if we didn't add any illustrative code at all but just spelled it out? #16186 |
|
Sure this will also do. |
|
Closing in favour of #16186 |
alternative to #16137 --------- Co-authored-by: Tee Ming <[email protected]>
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:
N/A)Tests
pnpm testand lint the project withpnpm lintandpnpm check(N/A)Changesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:. (N/A)Edits