Skip to content

Delete post button not working #1

@ikbentheo

Description

@ikbentheo

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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions