-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
Delete post button is not working anymore since there was a change. I found another solution:
## posts.remote.ts
export const updatePost = form(updatePostSchema, async ({ id, title, slug, content, action }) => {
if (action === 'delete') {
await delay(300)
await db.delete(table.posts).where(eq(table.posts.id, id))
redirect(303, `/admin`)
} else {
await delay(300)
console.log(title, slug, content)
await db.update(table.posts).set({ title, slug, content }).where(eq(table.posts.id, id))
}
})
## +page.svelte:
<form {...updatePost.enhance(({ submit }) => submit())}>
<label>
Title
<input {...updatePost.fields.title.as('text')} value={post.title} />
{#each updatePost.fields.title.issues() ?? [] as issue}
<p class="issue">{issue.message}</p>
{/each}
</label>
<label>
Slug
<input {...updatePost.fields.slug.as('text')} value={post.slug} />
{#each updatePost.fields.slug.issues() ?? [] as issue}
<p class="issue">{issue.message}</p>
{/each}
</label>
<label>
Content
<textarea {...updatePost.fields.content.as('text')} value={post.content}></textarea>
{#each updatePost.fields.content.issues() ?? [] as issue}
<p class="issue">{issue.message}</p>
{/each}
</label>
<input {...updatePost.fields.id.as('hidden', post.id.toString())} />
<button {...updatePost.fields.action.as('submit', 'update')} aria-busy={!!updatePost.pending}>Update</button>
<button {...updatePost.fields.action.as('submit', 'delete')} aria-busy={!!updatePost.pending}>Delete</button>
</form>
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels