Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AppForm extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- form: {},
- errors: {}
- };
- }
- componentWillMount() {
- if (this.props.data) {
- this.setState({form: this.props.data});
- }
- }
- render() {
- const {renderFunc} = this.props;
- return (
- <span className={styles['container']}>
- {renderFunc(this)}
- </span>
- );
- }
- /* PRIVATE */
- __onFormChange = (val, propName) => {
- const form = Object.assign({...this.state.form}, {[propName]: val});
- this.setState({form: form});
- };
- __submitForm(onSubmit) {
- const {actions: {triggerHideDialog}} = this.props;
- if (onSubmit) {
- onSubmit(this.state.form)
- .then(() => triggerHideDialog());
- } else {
- triggerHideDialog();
- }
- }
- /* PUBLIC FORM COMPONENTS */
- SubmitButton = ({onClick}) =>
- <RaisedButton
- label={'submit'}
- onClick={this.__submitForm.bind(this, onClick)}
- className={styles['button']}
- disabled={false}
- backgroundColor={primaryColor}
- labelColor={'#ffffff'}
- style={{width: '20%'}}/>;
- TextInput = ({prop, name}) => {
- const {form, errors} = this.state;
- return (
- <TextFieldWrapper
- name={prop}
- className={styles['input']}
- value={form[prop]}
- floatingLabelText={name}
- onChange={(proxy, val) => this.__onFormChange(val, prop)}
- errorText={errors[prop]}/>);
- };
- }
Add Comment
Please, Sign In to add comment