Guest User

Untitled

a guest
Nov 7th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. import React, {Component} from 'react'
  2. import { Alert, Button, Jumbotron, Form } from 'reactstrap';
  3. import FlatButton from 'material-ui/FlatButton';
  4. import TextInput from './TextInput'
  5.  
  6. export default class LoginForm extends Component {
  7. state = {
  8. username: '',
  9. password: ''
  10. }
  11.  
  12. handleInputChange = (event) => {
  13. const target = event.target;
  14. const value = target.type ===
  15. 'checkbox' ? target.checked : target.value;
  16. const name = target.name;
  17.  
  18. this.setState({
  19. [name]: value
  20. });
  21. }
  22.  
  23. componentDidMount() {
  24. this.primaryInput.focus();
  25. }
  26.  
  27. onSubmit = (event) => {
  28. event.preventDefault()
  29. this.props.onSubmit(this.state.username, this.state.password)
  30. }
  31.  
  32. render() {
  33. const errors = this.props.errors || {}
  34.  
  35. return (
  36. <Form onSubmit={this.onSubmit}>
  37. {errors.non_field_errors?<Alert color="danger">{errors.non_field_errors}</Alert>:""}
  38. <TextInput name="username" label="Username" error={errors.username} getRef={input => this.primaryInput = input} onChange={this.handleInputChange}/>
  39. <TextInput name="password" label="Password" error={errors.password} type="password" onChange={this.handleInputChange}/>
  40. <FlatButton label="Primary" type="submit" primary={true} />
  41. </Form>
  42.  
  43. )
  44. }
  45. }
Add Comment
Please, Sign In to add comment