Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to display validation failure for MUI Checkbox? #169

Closed
j18ter opened this issue Jul 27, 2017 · 4 comments
Closed

How to display validation failure for MUI Checkbox? #169

j18ter opened this issue Jul 27, 2017 · 4 comments

Comments

@j18ter
Copy link

j18ter commented Jul 27, 2017

The Checkbox component in redux-form-material-ui does not display validation errors. I tried creating a custom Checkbox component, but was utterly unsuccessful with the Checkbox from either material-ui or redux-form-material-ui as the starting point. Any suggestions how one can create a custom component from material-ui Checkbox that displays validation errors with redux-form?

@j18ter
Copy link
Author

j18ter commented Jul 28, 2017

Attempting to do this with a function like renderField from the examples failed miserably, but here is how I ended up doing it:

import React from 'react';
import { Checkbox } from 'redux-form-material-ui';
const styles = {
    error: {
        color: 'red',
        fontSize: 'small'
    }
};
class ValidatedCheckbox extends Checkbox {
    render() {
        const {meta: {touched, error}} = this.props;
        return (
            <div>
              {super.render()}
              {touched && error && <span style={styles.error}>{error}</span>}
            </div>
        );
    }
}

@mihirsoni
Copy link
Collaborator

It seems you have solved this.

@tandonrajiv
Copy link

tandonrajiv commented Jun 7, 2018

I am unable to add validation on checkbox can you please create a small form with this checkbox.

@pauloruizcares
Copy link

<Checkbox style={{ color: error ? "red" : undefined }} />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants