-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
style: use spaces for md files fp-50 (#51)
- Loading branch information
1 parent
972f948
commit 2f649a6
Showing
2 changed files
with
77 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,35 +17,35 @@ npm install form-payload | |
```html | ||
<!-- index.html --> | ||
<form name="general"> | ||
<label> | ||
Name | ||
<input type="text" name="name" value="Jon" /> | ||
</label> | ||
<label> | ||
Birthday | ||
<input type="date" name="birthday" value="2021-03-27" /> | ||
</label> | ||
<label> | ||
Friends Count | ||
<input type="number" name="friendsCount" value="1" /> | ||
</label> | ||
<fieldset name="friend"> | ||
<legend>Friend</legend> | ||
<label> | ||
Friend Name | ||
<input type="test" name="friendName" value="Kate" /> | ||
</label> | ||
</fieldset> | ||
<button type="submit">Submit</button> | ||
<label> | ||
Name | ||
<input type="text" name="name" value="Jon" /> | ||
</label> | ||
<label> | ||
Birthday | ||
<input type="date" name="birthday" value="2021-03-27" /> | ||
</label> | ||
<label> | ||
Friends Count | ||
<input type="number" name="friendsCount" value="1" /> | ||
</label> | ||
<fieldset name="friend"> | ||
<legend>Friend</legend> | ||
<label> | ||
Friend Name | ||
<input type="test" name="friendName" value="Kate" /> | ||
</label> | ||
</fieldset> | ||
<button type="submit">Submit</button> | ||
</form> | ||
|
||
... | ||
|
||
<form name="mailing"> | ||
<label> | ||
Mailing | ||
<input type="email" name="mail" name="[email protected]" /> | ||
</label> | ||
<label> | ||
Mailing | ||
<input type="email" name="mail" name="[email protected]" /> | ||
</label> | ||
</form> | ||
``` | ||
|
||
|
@@ -56,22 +56,22 @@ import { getFormValues, getControlValue } from 'form-payload'; | |
const { general: generalFormNode, mailing: mailingFormNode } = document.forms; | ||
|
||
generalFormNode.addEventListener('submit', (evt) => { | ||
evt.preventDefault(); | ||
|
||
console.log(getFormValues(generalFormNode)); | ||
// { | ||
// name: 'Jon', | ||
// birthday: Sat Mar 27 2021 18:06:42 GMT+0200 (Eastern European Standard Time), | ||
// friendsCount: 1, | ||
// friend: { | ||
// friendName: 'Kate', | ||
// }, | ||
// } | ||
evt.preventDefault(); | ||
|
||
console.log(getFormValues(generalFormNode)); | ||
// { | ||
// name: 'Jon', | ||
// birthday: Sat Mar 27 2021 18:06:42 GMT+0200 (Eastern European Standard Time), | ||
// friendsCount: 1, | ||
// friend: { | ||
// friendName: 'Kate', | ||
// }, | ||
// } | ||
}); | ||
|
||
mailingFormNode.addEventListener('change', (evt) => { | ||
console.log(getControlValue(evt.target)); | ||
// '[email protected]' | ||
console.log(getControlValue(evt.target)); | ||
// '[email protected]' | ||
}); | ||
``` | ||
|
||
|
@@ -85,45 +85,45 @@ _It doesn't matter which framework you use, you just need to pass the valid [HTM | |
import { getFormValues, getControlValue, ControlType } from 'form-payload'; | ||
|
||
const SimpleForm = () => { | ||
const handleSubmit = (evt: React.FormEvent<HTMLFormElement>) => { | ||
evt.preventDefault(); | ||
|
||
console.log(getFormValues(evt.target as HTMLFormElement)); | ||
// { | ||
// name: 'Jon', | ||
// birthday: Sat Mar 27 2021 18:06:42 GMT+0200 (Eastern European Standard Time), | ||
// } | ||
}; | ||
|
||
const handleChange = (evt: React.ChangeEvent<HTMLInputElement>) => { | ||
console.log(getControlValue(evt.target)); | ||
// '[email protected]' | ||
}; | ||
|
||
return ( | ||
<> | ||
<form onSubmit={handleSubmit}> | ||
<label> | ||
Name | ||
<input name="name" type={ControlType.TEXT} defaultValue="Jon" /> | ||
</label> | ||
<label> | ||
Date | ||
<input name="birthday" type={ControlType.DATE} defaultValue="2021-03-27" /> | ||
</label> | ||
<button type="submit">Submit</button> | ||
</form> | ||
|
||
... | ||
|
||
<form> | ||
<label> | ||
Mailing | ||
<input name="mail" type={ControlType.EMAIL} onChange={handleChange} /> | ||
</label> | ||
</form> | ||
</> | ||
); | ||
const handleSubmit = (evt: React.FormEvent<HTMLFormElement>) => { | ||
evt.preventDefault(); | ||
|
||
console.log(getFormValues(evt.target as HTMLFormElement)); | ||
// { | ||
// name: 'Jon', | ||
// birthday: Sat Mar 27 2021 18:06:42 GMT+0200 (Eastern European Standard Time), | ||
// } | ||
}; | ||
|
||
const handleChange = (evt: React.ChangeEvent<HTMLInputElement>) => { | ||
console.log(getControlValue(evt.target)); | ||
// '[email protected]' | ||
}; | ||
|
||
return ( | ||
<> | ||
<form onSubmit={handleSubmit}> | ||
<label> | ||
Name | ||
<input name="name" type={ControlType.TEXT} defaultValue="Jon" /> | ||
</label> | ||
<label> | ||
Date | ||
<input name="birthday" type={ControlType.DATE} defaultValue="2021-03-27" /> | ||
</label> | ||
<button type="submit">Submit</button> | ||
</form> | ||
|
||
... | ||
|
||
<form> | ||
<label> | ||
Mailing | ||
<input name="mail" type={ControlType.EMAIL} onChange={handleChange} /> | ||
</label> | ||
</form> | ||
</> | ||
); | ||
}; | ||
``` | ||
|
||
|