Created
November 4, 2018 14:20
-
-
Save cauldyclark15/93decbe62ae0861a53891c9d3cc8bcdf to your computer and use it in GitHub Desktop.
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
function SampleForm({ onSubmit, form: {getFieldDecorator} }) { | |
return ( | |
<form | |
onSubmit={event => { | |
event.preventDefault(); | |
const elementValues = getElementValues(event.target); | |
onSubmit(elementValues); | |
}} | |
> | |
<LabeledInput label="email" /> | |
<LabeledInput label="password" type="password" /> | |
<Button data-testid="f1-submit" htmlType="submit"> | |
submit | |
</Button> | |
</form> | |
); | |
} | |
function LabeledInput({ label, type = 'text', autoComplete = 'off' }) { | |
return ( | |
<div> | |
<label htmlFor={label}>{label}</label> | |
<input | |
id={label} | |
placeholder={label} | |
type={type} | |
autoComplete={autoComplete} | |
/> | |
</div> | |
); | |
} | |
function getElementValues(formNode) { | |
return Object.getOwnPropertyNames(formNode.elements).reduce((obj, key) => { | |
obj[key] = formNode.elements[key].value; | |
return obj; | |
}, {}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment