Skip to content

Commit

Permalink
Upgrade conform version (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
edmundhung committed Jul 20, 2023
1 parent 92fe28b commit 7110162
Show file tree
Hide file tree
Showing 65 changed files with 466 additions and 644 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ validation. It's about a better user experience!

Here are the requirements:

- `title` is required, minimum length of 1, maximum length of 100
- `content` is required, minimum length of 1, maximum length of 10000
- `title` is required, maximum length of 100
- `content` is required, maximum length of 10000

You can use native HTML form validation attributes on the `input` and `textarea`
to accomplish this. `required`, `minlength`, and `maxlength` are the attributes
to accomplish this. `required`, and `maxlength` are the attributes
you'll need.

- [📜 Form Validation on MDN](https://developer.mozilla.org/en-US/docs/Learn/Forms/Form_validation)
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"typecheck": "tsc"
},
"dependencies": {
"@conform-to/react": "^0.7.3",
"@conform-to/zod": "^0.7.3",
"@conform-to/react": "0.8.0-pre.1",
"@conform-to/zod": "0.8.0-pre.1",
"@mswjs/data": "^0.13.0",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-slot": "^1.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export default function NoteEdit() {
name="title"
defaultValue={data.note.title}
required
minLength={1}
maxLength={100}
/>
</div>
Expand All @@ -69,7 +68,6 @@ export default function NoteEdit() {
name="content"
defaultValue={data.note.content}
required
minLength={1}
maxLength={10000}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"typecheck": "tsc"
},
"dependencies": {
"@conform-to/react": "^0.7.3",
"@conform-to/zod": "^0.7.3",
"@conform-to/react": "0.8.0-pre.1",
"@conform-to/zod": "0.8.0-pre.1",
"@mswjs/data": "^0.13.0",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-slot": "^1.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export default function NoteEdit() {
name="title"
defaultValue={data.note.title}
required
minLength={1}
maxLength={100}
/>
{/* 🐨 add the title error messages here */}
Expand All @@ -84,7 +83,6 @@ export default function NoteEdit() {
name="content"
defaultValue={data.note.content}
required
minLength={1}
maxLength={10000}
/>
{/* 🐨 add content the error messages here */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"typecheck": "tsc"
},
"dependencies": {
"@conform-to/react": "^0.7.3",
"@conform-to/zod": "^0.7.3",
"@conform-to/react": "0.8.0-pre.1",
"@conform-to/zod": "0.8.0-pre.1",
"@mswjs/data": "^0.13.0",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-slot": "^1.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ type ActionErrors = {
}
}

const titleMinLength = 1
const titleMaxLength = 100
const contentMinLength = 1
const contentMaxLength = 10000

export async function action({ request, params }: DataFunctionArgs) {
Expand All @@ -56,14 +54,14 @@ export async function action({ request, params }: DataFunctionArgs) {
},
}

if (title.length < titleMinLength) {
errors.fieldErrors.title.push('Title must be at least 1 character')
if (title === '') {
errors.fieldErrors.title.push('Title is required')
}
if (title.length > titleMaxLength) {
errors.fieldErrors.title.push('Title must be at most 100 characters')
}
if (content.length < contentMinLength) {
errors.fieldErrors.content.push('Content must be at least 1 character')
if (content === '') {
errors.fieldErrors.content.push('Content is required')
}
if (content.length > contentMaxLength) {
errors.fieldErrors.content.push('Content must be at most 10000 characters')
Expand Down Expand Up @@ -117,7 +115,6 @@ export default function NoteEdit() {
name="title"
defaultValue={data.note.title}
required
minLength={titleMinLength}
maxLength={titleMaxLength}
/>
<div className="min-h-[32px] px-4 pb-3 pt-1">
Expand All @@ -131,7 +128,6 @@ export default function NoteEdit() {
name="content"
defaultValue={data.note.content}
required
minLength={contentMinLength}
maxLength={contentMaxLength}
/>
<div className="min-h-[32px] px-4 pb-3 pt-1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"typecheck": "tsc"
},
"dependencies": {
"@conform-to/react": "^0.7.3",
"@conform-to/zod": "^0.7.3",
"@conform-to/react": "0.8.0-pre.1",
"@conform-to/zod": "0.8.0-pre.1",
"@mswjs/data": "^0.13.0",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-slot": "^1.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ type ActionErrors = {
}
}

const titleMinLength = 1
const titleMaxLength = 100
const contentMinLength = 1
const contentMaxLength = 10000

export async function action({ request, params }: DataFunctionArgs) {
Expand All @@ -56,14 +54,14 @@ export async function action({ request, params }: DataFunctionArgs) {
},
}

if (title.length < titleMinLength) {
errors.fieldErrors.title.push('Title must be at least 1 character')
if (title === '') {
errors.fieldErrors.title.push('Title is required')
}
if (title.length > titleMaxLength) {
errors.fieldErrors.title.push('Title must be at most 100 characters')
}
if (content.length < contentMinLength) {
errors.fieldErrors.content.push('Content must be at least 1 character')
if (content === '') {
errors.fieldErrors.content.push('Content is required')
}
if (content.length > contentMaxLength) {
errors.fieldErrors.content.push('Content must be at most 10000 characters')
Expand Down Expand Up @@ -122,7 +120,6 @@ export default function NoteEdit() {
name="title"
defaultValue={data.note.title}
required
minLength={titleMinLength}
maxLength={titleMaxLength}
/>
<div className="min-h-[32px] px-4 pb-3 pt-1">
Expand All @@ -136,7 +133,6 @@ export default function NoteEdit() {
name="content"
defaultValue={data.note.content}
required
minLength={contentMinLength}
maxLength={contentMaxLength}
/>
<div className="min-h-[32px] px-4 pb-3 pt-1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"typecheck": "tsc"
},
"dependencies": {
"@conform-to/react": "^0.7.3",
"@conform-to/zod": "^0.7.3",
"@conform-to/react": "0.8.0-pre.1",
"@conform-to/zod": "0.8.0-pre.1",
"@mswjs/data": "^0.13.0",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-slot": "^1.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ type ActionErrors = {
}
}

const titleMinLength = 1
const titleMaxLength = 100
const contentMinLength = 1
const contentMaxLength = 10000

export async function action({ request, params }: DataFunctionArgs) {
Expand All @@ -57,14 +55,14 @@ export async function action({ request, params }: DataFunctionArgs) {
},
}

if (title.length < titleMinLength) {
errors.fieldErrors.title.push('Title must be at least 1 character')
if (title === '') {
errors.fieldErrors.title.push('Title is required')
}
if (title.length > titleMaxLength) {
errors.fieldErrors.title.push('Title must be at most 100 characters')
}
if (content.length < contentMinLength) {
errors.fieldErrors.content.push('Content must be at least 1 character')
if (content === '') {
errors.fieldErrors.content.push('Content is required')
}
if (content.length > contentMaxLength) {
errors.fieldErrors.content.push('Content must be at most 10000 characters')
Expand Down Expand Up @@ -126,7 +124,6 @@ export default function NoteEdit() {
name="title"
defaultValue={data.note.title}
required
minLength={titleMinLength}
maxLength={titleMaxLength}
/>
<div className="min-h-[32px] px-4 pb-3 pt-1">
Expand All @@ -140,7 +137,6 @@ export default function NoteEdit() {
name="content"
defaultValue={data.note.content}
required
minLength={contentMinLength}
maxLength={contentMaxLength}
/>
<div className="min-h-[32px] px-4 pb-3 pt-1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"typecheck": "tsc"
},
"dependencies": {
"@conform-to/react": "^0.7.3",
"@conform-to/zod": "^0.7.3",
"@conform-to/react": "0.8.0-pre.1",
"@conform-to/zod": "0.8.0-pre.1",
"@mswjs/data": "^0.13.0",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-slot": "^1.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ type ActionErrors = {
}
}

const titleMinLength = 1
const titleMaxLength = 100
const contentMinLength = 1
const contentMaxLength = 10000

export async function action({ request, params }: DataFunctionArgs) {
Expand All @@ -57,14 +55,14 @@ export async function action({ request, params }: DataFunctionArgs) {
},
}

if (title.length < titleMinLength) {
errors.fieldErrors.title.push('Title must be at least 1 character')
if (title === '') {
errors.fieldErrors.title.push('Title is required')
}
if (title.length > titleMaxLength) {
errors.fieldErrors.title.push('Title must be at most 100 characters')
}
if (content.length < contentMinLength) {
errors.fieldErrors.content.push('Content must be at least 1 character')
if (content === '') {
errors.fieldErrors.content.push('Content is required')
}
if (content.length > contentMaxLength) {
errors.fieldErrors.content.push('Content must be at most 10000 characters')
Expand Down Expand Up @@ -133,7 +131,6 @@ export default function NoteEdit() {
name="title"
defaultValue={data.note.title}
required
minLength={titleMinLength}
maxLength={titleMaxLength}
/>
<div className="min-h-[32px] px-4 pb-3 pt-1">
Expand All @@ -148,7 +145,6 @@ export default function NoteEdit() {
name="content"
defaultValue={data.note.content}
required
minLength={contentMinLength}
maxLength={contentMaxLength}
/>
<div className="min-h-[32px] px-4 pb-3 pt-1">
Expand Down
4 changes: 2 additions & 2 deletions exercises/02.accessibility/01.problem.labels/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"typecheck": "tsc"
},
"dependencies": {
"@conform-to/react": "^0.7.3",
"@conform-to/zod": "^0.7.3",
"@conform-to/react": "0.8.0-pre.1",
"@conform-to/zod": "0.8.0-pre.1",
"@mswjs/data": "^0.13.0",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-slot": "^1.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ type ActionErrors = {
}
}

const titleMinLength = 1
const titleMaxLength = 100
const contentMinLength = 1
const contentMaxLength = 10000

export async function action({ request, params }: DataFunctionArgs) {
Expand All @@ -57,14 +55,14 @@ export async function action({ request, params }: DataFunctionArgs) {
},
}

if (title.length < titleMinLength) {
errors.fieldErrors.title.push('Title must be at least 1 character')
if (title === '') {
errors.fieldErrors.title.push('Title is required')
}
if (title.length > titleMaxLength) {
errors.fieldErrors.title.push('Title must be at most 100 characters')
}
if (content.length < contentMinLength) {
errors.fieldErrors.content.push('Content must be at least 1 character')
if (content === '') {
errors.fieldErrors.content.push('Content is required')
}
if (content.length > contentMaxLength) {
errors.fieldErrors.content.push('Content must be at most 10000 characters')
Expand Down Expand Up @@ -128,7 +126,6 @@ export default function NoteEdit() {
name="title"
defaultValue={data.note.title}
required
minLength={titleMinLength}
maxLength={titleMaxLength}
/>
<div className="min-h-[32px] px-4 pb-3 pt-1">
Expand All @@ -142,7 +139,6 @@ export default function NoteEdit() {
name="content"
defaultValue={data.note.content}
required
minLength={contentMinLength}
maxLength={contentMaxLength}
/>
<div className="min-h-[32px] px-4 pb-3 pt-1">
Expand Down
4 changes: 2 additions & 2 deletions exercises/02.accessibility/01.solution.labels/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"typecheck": "tsc"
},
"dependencies": {
"@conform-to/react": "^0.7.3",
"@conform-to/zod": "^0.7.3",
"@conform-to/react": "0.8.0-pre.1",
"@conform-to/zod": "0.8.0-pre.1",
"@mswjs/data": "^0.13.0",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-slot": "^1.0.2",
Expand Down
4 changes: 1 addition & 3 deletions exercises/02.accessibility/02.problem.aria/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ case). So when the `title` looks good, it should render HTML like this:
id="note-title"
name="title"
required=""
minlength="1"
maxlength="100"
value="Basic Koala Facts"
/>
Expand All @@ -26,15 +25,14 @@ case). So when the `title` looks good, it should render HTML like this:

And when the `title` has an error, it should render HTML like this:

```html lines=11,12
```html lines=10,11
<div>
<label class="..." for="note-title">Title</label>
<input
class="..."
id="note-title"
name="title"
required=""
minlength="1"
maxlength="100"
value="Basic Koala Facts"
aria-invalid="true"
Expand Down
Loading

0 comments on commit 7110162

Please sign in to comment.