46 | Success! 47 |
48 | 49 | 50 | 73 | 74 | 82 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@louislschvn/nuxt-form", 3 | "version": "1.0.6", 4 | "description": "Add a useForm composable to Nuxt, and a createValidationError function to validate forms in Nitro", 5 | "repository": { 6 | "type": "git", 7 | "url": "git+https://github.com/LouisLSCHVN/nuxt-form.git" 8 | }, 9 | "license": "MIT", 10 | "type": "module", 11 | "exports": { 12 | ".": { 13 | "types": "./dist/types.d.ts", 14 | "import": "./dist/module.mjs", 15 | "require": "./dist/module.cjs" 16 | } 17 | }, 18 | "main": "./dist/module.cjs", 19 | "types": "./dist/types.d.ts", 20 | "files": [ 21 | "dist" 22 | ], 23 | "scripts": { 24 | "prepack": "nuxt-module-build build", 25 | "dev": "nuxi dev playground", 26 | "dev:build": "nuxi build playground", 27 | "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground", 28 | "release": "npm run lint && npm run test && npm run prepack && changelogen --release && npm publish --access public && git push --follow-tags", 29 | "lint": "eslint .", 30 | "test": "vitest run", 31 | "test:watch": "vitest watch", 32 | "test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit" 33 | }, 34 | "dependencies": { 35 | "@nuxt/kit": "^3.13.1", 36 | "zod": "^3.23.8" 37 | }, 38 | "devDependencies": { 39 | "@nuxt/devtools": "^1.4.1", 40 | "@nuxt/eslint-config": "^0.5.5", 41 | "@nuxt/module-builder": "^0.8.3", 42 | "@nuxt/schema": "^3.13.1", 43 | "@nuxt/test-utils": "^3.14.1", 44 | "@types/node": "latest", 45 | "changelogen": "^0.5.5", 46 | "eslint": "^9.9.1", 47 | "nuxt": "^3.13.0", 48 | "typescript": "latest", 49 | "vitest": "^2.0.5", 50 | "vue-tsc": "^2.1.6" 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Nuxt Form 2 | 3 | [![npm version][npm-version-src]][npm-version-href] 4 | [![npm downloads][npm-downloads-src]][npm-downloads-href] 5 | [![License][license-src]][license-href] 6 | [![Nuxt][nuxt-src]][nuxt-href] 7 | 8 | My new Nuxt module for doing amazing things. 9 | 10 | - [✨ Release Notes](/CHANGELOG.md) 11 | 12 | 13 | 14 | ## Features 15 | 16 | - ⛰ Form handling similar to Inertia/Vue's useForm 17 | - 🚠 Backend validation with Zod 18 | - 🌲 Frontend form state management 19 | - 🏔 Easy error handling and validation 20 | 21 | ## Quick Setup 22 | 23 | Install the module to your Nuxt application with one command: 24 | 25 | ```bash 26 | npx nuxi module add @louislschvn/nuxt-form 27 | ``` 28 | 29 | That's it! You can now use Nuxt Form in your Nuxt app ✨ 30 | 31 | ## Documentation 32 | 33 | ### Backend Usage 34 | 35 | Nuxt Form provides a utility function `createValidationError` for easy backend validation: 36 | 37 | ```javascript 38 | import { createUserValidator } from '../validators' 39 | 40 | export default defineEventHandler(async (event) => { 41 | const result = await readValidatedBody(event, createUserValidator.safeParse) 42 | if (!result.success) { 43 | return createValidationError(result.error) 44 | } 45 | // Store in database.. 46 | return { statusCode: 201, message: 'success' } 47 | }) 48 | ``` 49 | 50 | ### Frontend Usage 51 | 52 | On the frontend, you can use the `useForm` composable to handle form state and submission: 53 | 54 | ```vue 55 | 56 | 65 |Success!
66 | 67 | 68 | 90 | ``` 91 | 92 | This setup provides a seamless integration between frontend form handling and backend validation, similar to the functionality offered by Inertia.js and Vue's useForm, but tailored for Nuxt applications. 93 | 94 | ## File Uploads 95 | 96 | Nuxt Form also supports file uploads in a simple and efficient way. You can manage file uploads alongside your form data, and it even provides upload progress tracking. 97 | 98 | ### Example of File Upload 99 | 100 | In the example below, you can see how to add a file upload input to your form. The file selected will be sent with the rest of the form data when submitted. 101 | 102 | ```vue 103 | 104 | 124 | 125 | 126 | 135 | ``` 136 | 137 | ### Key Features of File Handling: 138 | 139 | - Automatically manage file uploads with the form data. 140 | - Track upload progress with a visual progress bar. 141 | 142 | ## Todo 143 | 144 | - [X] Handle file uploads 145 | - [X] Make success state natively available in the composable 146 | 147 | ## Contribution 148 | 149 |