Guest User

Untitled

a guest
Dec 17th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. class AppForm extends React.Component {
  2. constructor(props) {
  3. super(props);
  4. this.state = {
  5. form: {},
  6. errors: {}
  7. };
  8. }
  9.  
  10. componentWillMount() {
  11. if (this.props.data) {
  12. this.setState({form: this.props.data});
  13. }
  14. }
  15.  
  16. render() {
  17. const {renderFunc} = this.props;
  18. return (
  19. <span className={styles['container']}>
  20. {renderFunc(this)}
  21. </span>
  22. );
  23. }
  24.  
  25. /* PRIVATE */
  26. __onFormChange = (val, propName) => {
  27. const form = Object.assign({...this.state.form}, {[propName]: val});
  28. this.setState({form: form});
  29. };
  30.  
  31. __submitForm(onSubmit) {
  32. const {actions: {triggerHideDialog}} = this.props;
  33. if (onSubmit) {
  34. onSubmit(this.state.form)
  35. .then(() => triggerHideDialog());
  36. } else {
  37. triggerHideDialog();
  38. }
  39. }
  40.  
  41. /* PUBLIC FORM COMPONENTS */
  42. SubmitButton = ({onClick}) =>
  43. <RaisedButton
  44. label={'submit'}
  45. onClick={this.__submitForm.bind(this, onClick)}
  46. className={styles['button']}
  47. disabled={false}
  48. backgroundColor={primaryColor}
  49. labelColor={'#ffffff'}
  50. style={{width: '20%'}}/>;
  51.  
  52. TextInput = ({prop, name}) => {
  53. const {form, errors} = this.state;
  54. return (
  55. <TextFieldWrapper
  56. name={prop}
  57. className={styles['input']}
  58. value={form[prop]}
  59. floatingLabelText={name}
  60. onChange={(proxy, val) => this.__onFormChange(val, prop)}
  61. errorText={errors[prop]}/>);
  62. };
  63. }
Add Comment
Please, Sign In to add comment