Skip to content

Commit

Permalink
Support for Vine 2.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
ciscoheat committed Nov 15, 2024
1 parent ae643b2 commit ba7de2a
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ Headlines: Added, Changed, Deprecated, Removed, Fixed, Security
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Support for Vine 2.0.

## [2.20.0] - 2024-10-18

### Added
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"@sinclair/typebox": ">=0.32.30 <1",
"@sveltejs/kit": "1.x || 2.x",
"@typeschema/class-validator": "^0.3.0",
"@vinejs/vine": "^1.8.0",
"@vinejs/vine": "^1.8.0 || ^2.0.0",
"arktype": ">=2.0.0-rc.8",
"class-validator": "^0.14.1",
"effect": "^3.8.2",
Expand Down Expand Up @@ -165,7 +165,7 @@
"@gcornut/valibot-json-schema": "^0.31.0",
"@sinclair/typebox": "^0.32.35",
"@typeschema/class-validator": "^0.3.0",
"@vinejs/vine": "^1.8.0",
"@vinejs/vine": "^2.0.0",
"arktype": "2.0.0-rc.8",
"class-validator": "^0.14.1",
"effect": "^3.9.1",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions src/routes/(v2)/v2/vine/+page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { vine } from '$lib/adapters/vine.js';
import { message, superValidate } from '$lib/server/index.js';
import { schema } from './schema.js';
import { fail } from '@sveltejs/kit';

const defaults = { name: '', email: '' };

export const load = async () => {
const form = await superValidate(vine(schema, { defaults }));
return { form };
};

export const actions = {
default: async ({ request }) => {
const formData = await request.formData();
console.log(formData);

const form = await superValidate(formData, vine(schema, { defaults }));
console.log(form);

if (!form.valid) return fail(400, { form });

return message(form, 'Posted OK!');
}
};
54 changes: 54 additions & 0 deletions src/routes/(v2)/v2/vine/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<script lang="ts">
import { superForm } from '$lib/client/index.js';
import SuperDebug from '$lib/client/SuperDebug.svelte';
//import { zod } from '$lib/adapters/zod.js'
//import { schema } from './schema.js';
export let data;
const { form, errors, tainted, message, enhance } = superForm(data.form, {
taintedMessage: false
//dataType: 'json',
//validators: zod(schema)
});
</script>

<SuperDebug data={{ $form, $errors, $tainted }} />

{#if $message}<h4>{$message}</h4>{/if}

<form method="POST" use:enhance>
<label>
Name: <input
name="name"
bind:value={$form.name}
aria-invalid={$errors.name ? 'true' : undefined}
/>
{#if $errors.name}<span class="invalid">{$errors.name}</span>{/if}
</label>
<label>
Email: <input
name="email"
bind:value={$form.email}
aria-invalid={$errors.email ? 'true' : undefined}
/>
{#if $errors.email}<span class="invalid">{$errors.email}</span>{/if}
</label>
<div>
<button>Submit</button>
</div>
</form>

<style lang="scss">
form {
margin: 2rem 0;
input {
background-color: #dedede;
}
.invalid {
color: crimson;
}
}
</style>
6 changes: 6 additions & 0 deletions src/routes/(v2)/v2/vine/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Vine from '@vinejs/vine';

export const schema = Vine.object({
name: Vine.string().minLength(2),
email: Vine.string().email()
});

0 comments on commit ba7de2a

Please sign in to comment.