mirror of
https://github.com/cupcakearmy/formhero.git
synced 2025-09-05 22:00:39 +00:00
rename auto to field
This commit is contained in:
@@ -4,32 +4,34 @@ import ReactDOM from 'react-dom'
|
||||
import { useForm } from '../dist'
|
||||
|
||||
const Index: React.FC = () => {
|
||||
const { field, form, errors } = useForm({
|
||||
awesome: true,
|
||||
})
|
||||
|
||||
const { auto, form, errors } = useForm({
|
||||
awesome: true,
|
||||
})
|
||||
return (
|
||||
<form
|
||||
onSubmit={e => {
|
||||
e.preventDefault()
|
||||
console.log(form)
|
||||
}}
|
||||
>
|
||||
<h1>Custom</h1>
|
||||
|
||||
return (
|
||||
<form onSubmit={e => {
|
||||
e.preventDefault()
|
||||
console.log(form)
|
||||
}}>
|
||||
<label>
|
||||
<input
|
||||
type="checkbox"
|
||||
{...field('awesome', {
|
||||
setter: 'checked',
|
||||
getter: 'onChange',
|
||||
extractor: e => e.target.checked,
|
||||
})}
|
||||
/>
|
||||
Is it awesome?
|
||||
</label>
|
||||
|
||||
<h1>Custom</h1>
|
||||
|
||||
<label>
|
||||
<input type="checkbox" {...auto('awesome', {
|
||||
setter: 'checked',
|
||||
getter: 'onChange',
|
||||
extractor: (e) => e.target.checked
|
||||
})} />
|
||||
Is it awesome?
|
||||
</label>
|
||||
|
||||
<input type="submit" />
|
||||
|
||||
</form>
|
||||
)
|
||||
<input type="submit" />
|
||||
</form>
|
||||
)
|
||||
}
|
||||
|
||||
ReactDOM.render(<Index />, document.getElementById('custom'))
|
||||
ReactDOM.render(<Index />, document.getElementById('custom'))
|
||||
|
@@ -4,50 +4,52 @@ import ReactDOM from 'react-dom'
|
||||
import { useForm } from '../'
|
||||
|
||||
const Index: React.FC = () => {
|
||||
const { field, form, errors, isValid } = useForm(
|
||||
{
|
||||
username: '',
|
||||
email: '',
|
||||
password: '',
|
||||
},
|
||||
{
|
||||
username: value => value.length > 3,
|
||||
email: {
|
||||
validator: /@/,
|
||||
message: 'Must contain an @',
|
||||
},
|
||||
password: [
|
||||
{
|
||||
validator: /[A-Z]/,
|
||||
message: 'Must contain an uppercase letter',
|
||||
},
|
||||
{
|
||||
validator: /[\d]/,
|
||||
message: 'Must contain a digit',
|
||||
},
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
const { auto, form, errors, isValid } = useForm({
|
||||
username: '',
|
||||
email: '',
|
||||
password: ''
|
||||
}, {
|
||||
username: value => value.length > 3,
|
||||
email: {
|
||||
validator: /@/,
|
||||
message: 'Must contain an @',
|
||||
},
|
||||
password: [
|
||||
{
|
||||
validator: /[A-Z]/,
|
||||
message: 'Must contain an uppercase letter'
|
||||
},
|
||||
{
|
||||
validator: /[\d]/,
|
||||
message: 'Must contain a digit'
|
||||
},
|
||||
]
|
||||
})
|
||||
return (
|
||||
<form
|
||||
onSubmit={e => {
|
||||
e.preventDefault()
|
||||
if (isValid) console.log(form)
|
||||
}}
|
||||
>
|
||||
<h1>Errors & Validation</h1>
|
||||
|
||||
return (
|
||||
<form onSubmit={(e) => {
|
||||
e.preventDefault()
|
||||
if (isValid) console.log(form)
|
||||
}}>
|
||||
<input {...field('username')} placeholder="Username" />
|
||||
{errors.username && 'Must be longer than 3'}
|
||||
|
||||
<h1>Errors & Validation</h1>
|
||||
<input {...field('email')} placeholder="EMail" />
|
||||
{errors.email}
|
||||
|
||||
<input {...auto('username')} placeholder="Username" />
|
||||
{errors.username && 'Must be longer than 3'}
|
||||
<input {...field('password')} placeholder="Password" type="password" />
|
||||
{errors.password}
|
||||
|
||||
<input {...auto('email')} placeholder="EMail" />
|
||||
{errors.email}
|
||||
|
||||
<input {...auto('password')} placeholder="Password" type="password" />
|
||||
{errors.password}
|
||||
|
||||
<input type="submit" />
|
||||
|
||||
</form>
|
||||
)
|
||||
<input type="submit" />
|
||||
</form>
|
||||
)
|
||||
}
|
||||
|
||||
ReactDOM.render(<Index />, document.getElementById('errors'))
|
||||
ReactDOM.render(<Index />, document.getElementById('errors'))
|
||||
|
@@ -1,67 +1,64 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Form Hero</title>
|
||||
<style>
|
||||
body {
|
||||
padding: 1em;
|
||||
margin: 0;
|
||||
font-family: 'Courier New', Courier, monospace;
|
||||
}
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Form Hero</title>
|
||||
<style>
|
||||
body {
|
||||
padding: 1em;
|
||||
margin: 0;
|
||||
font-family: 'Courier New', Courier, monospace;
|
||||
}
|
||||
section {
|
||||
text-align: center;
|
||||
max-width: 25em;
|
||||
margin: 1em auto;
|
||||
padding: 1em;
|
||||
background-color: #f3f3f3;
|
||||
border-radius: 0.5em;
|
||||
box-shadow: 0 8px 16px -16px rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
section {
|
||||
text-align: center;
|
||||
max-width: 25em;
|
||||
margin: 1em auto;
|
||||
padding: 1em;
|
||||
background-color: #f3f3f3;
|
||||
border-radius: .5em;
|
||||
box-shadow: 0 8px 16px -16px rgba(0, 0, 0, .5);
|
||||
}
|
||||
input {
|
||||
font-size: 1.25em;
|
||||
display: block;
|
||||
padding: 0.5em 1em;
|
||||
margin-top: 0.5em;
|
||||
border-radius: 1em;
|
||||
width: 100%;
|
||||
outline: none;
|
||||
border: 0.15em solid white;
|
||||
}
|
||||
|
||||
input {
|
||||
font-size: 1.25em;
|
||||
display: block;
|
||||
padding: .5em 1em;
|
||||
margin-top: .5em;
|
||||
border-radius: 1em;
|
||||
width: 100%;
|
||||
outline: none;
|
||||
border: .15em solid white;
|
||||
}
|
||||
input:focus,
|
||||
input:hover {
|
||||
border-color: #31def5;
|
||||
}
|
||||
|
||||
input:focus,
|
||||
input:hover {
|
||||
border-color: #31def5;
|
||||
input[type='submit'] {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
}
|
||||
input[type='checkbox'] {
|
||||
display: inline;
|
||||
width: initial;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
input[type="submit"] {
|
||||
cursor: pointer;
|
||||
}
|
||||
<body>
|
||||
<section>
|
||||
<h3>Open the console to see the submitted data</h3>
|
||||
</section>
|
||||
<section id="simple"></section>
|
||||
<section id="errors"></section>
|
||||
<section id="select"></section>
|
||||
<section id="custom"></section>
|
||||
|
||||
input[type="checkbox"] {
|
||||
display: inline;
|
||||
width: initial;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<section>
|
||||
<h3>Open the console to see the submitted data</h3>
|
||||
</section>
|
||||
<section id="simple"></section>
|
||||
<section id="errors"></section>
|
||||
<section id="select"></section>
|
||||
<section id="custom"></section>
|
||||
|
||||
<script src="./simple.tsx"></script>
|
||||
<script src="./errorsAndValidation.tsx"></script>
|
||||
<script src="./select.tsx"></script>
|
||||
<script src="./custom.tsx"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
<script src="./simple.tsx"></script>
|
||||
<script src="./errorsAndValidation.tsx"></script>
|
||||
<script src="./select.tsx"></script>
|
||||
<script src="./custom.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
@@ -4,30 +4,29 @@ import ReactDOM from 'react-dom'
|
||||
import { useForm } from '../dist'
|
||||
|
||||
const Index: React.FC = () => {
|
||||
const { field, form, errors } = useForm({
|
||||
type: 'formhero',
|
||||
})
|
||||
|
||||
const { auto, form, errors } = useForm({
|
||||
type: 'formhero',
|
||||
})
|
||||
return (
|
||||
<form
|
||||
onSubmit={e => {
|
||||
e.preventDefault()
|
||||
console.log(form)
|
||||
}}
|
||||
>
|
||||
<h1>Select</h1>
|
||||
|
||||
return (
|
||||
<form onSubmit={e => {
|
||||
e.preventDefault()
|
||||
console.log(form)
|
||||
}}>
|
||||
<select {...field('type')}>
|
||||
<option value="redux-form">Redux-Form</option>
|
||||
<option value="react-hook-forms">React-Hook-Forms</option>
|
||||
<option value="formik">Formik</option>
|
||||
<option value="formhero">FormHero</option>
|
||||
</select>
|
||||
|
||||
<h1>Select</h1>
|
||||
|
||||
<select {...auto('type')}>
|
||||
<option value="redux-form">Redux-Form</option>
|
||||
<option value="react-hook-forms">React-Hook-Forms</option>
|
||||
<option value="formik">Formik</option>
|
||||
<option value="formhero">FormHero</option>
|
||||
</select>
|
||||
|
||||
<input type="submit" />
|
||||
|
||||
</form>
|
||||
)
|
||||
<input type="submit" />
|
||||
</form>
|
||||
)
|
||||
}
|
||||
|
||||
ReactDOM.render(<Index />, document.getElementById('select'))
|
||||
ReactDOM.render(<Index />, document.getElementById('select'))
|
||||
|
@@ -4,27 +4,26 @@ import ReactDOM from 'react-dom'
|
||||
import { useForm } from '../dist'
|
||||
|
||||
const Index: React.FC = () => {
|
||||
const { field, form, errors } = useForm({
|
||||
username: 'unicorn',
|
||||
password: '',
|
||||
})
|
||||
|
||||
const { auto, form, errors } = useForm({
|
||||
username: 'unicorn',
|
||||
password: '',
|
||||
})
|
||||
return (
|
||||
<form
|
||||
onSubmit={e => {
|
||||
e.preventDefault()
|
||||
console.log(form)
|
||||
}}
|
||||
>
|
||||
<h1>Simple</h1>
|
||||
|
||||
return (
|
||||
<form onSubmit={e => {
|
||||
e.preventDefault()
|
||||
console.log(form)
|
||||
}}>
|
||||
<input {...field('username')} placeholder="Username" />
|
||||
<input {...field('password')} placeholder="Password" type="password" />
|
||||
|
||||
<h1>Simple</h1>
|
||||
|
||||
<input {...auto('username')} placeholder="Username" />
|
||||
<input {...auto('password')} placeholder="Password" type="password" />
|
||||
|
||||
<input type="submit" />
|
||||
|
||||
</form>
|
||||
)
|
||||
<input type="submit" />
|
||||
</form>
|
||||
)
|
||||
}
|
||||
|
||||
ReactDOM.render(<Index />, document.getElementById('simple'))
|
||||
ReactDOM.render(<Index />, document.getElementById('simple'))
|
||||
|
Reference in New Issue
Block a user