1

I have a form set up with redux-form to supply the initial values (although it also handles the values so that they're changed in the redux store too) as so below.

But my checkboxes are unable to be interacted with. They always stay checked (which is their initial value based off the model supplied)

My render method: (I copied the renderCheckbox from this documentation.

render() {
    const {classes} = this.props;

    const renderTextField = ({input, label, meta: { touched, error }, ...custom}) => (
        <TextField
            error={touched && error}
            {...input}
            {...custom}
        />
    );

    const renderCheckbox = ({ input, label }) => (
        <Checkbox
            label={label}
            checked={input.value ? true : false}
            //onCheck={input.onChange} // I had this enabled but it didn't do anything
        />
    );
    const { submit, handleSubmit, pristine, reset, submitting } = this.props;

    return (
        <form onSubmit={handleSubmit(this.props.sendSubmit)}>
            <Paper className={classes.sectionPaper}>
                <CardContent>
                    <Typography className={classes.sectionHeader}>Artifact Info</Typography>
                    <Divider />
                </CardContent>
                <CardContent>
                    <Grid fluid>
                        <Row>
                            <Col xs={12} lg={4}>
                                <CardContent className={classes.artifactCardContent}>
                                    <Typography>Artifact Name</Typography>
                                    <Divider />
                                    <Field
                                        fullWidth
                                        name="Name"
                                        component={renderTextField}
                                        label="Artifact Name"
                                    />
                                </CardContent>
                            </Col>
                            <Col xs={6} lg={1}>
                                <CardContent className={classes.artifactCardContent}>
                                    <Typography>Mythic?</Typography>
                                    <Divider />
                                    <Field
                                        name="Mythic"
                                        component={renderCheckbox}
                                        label="Mythic"
                                    />
                                </CardContent>
                            </Col>
                        </Row>
                    </Grid>
                </CardContent>
            </Paper>



        </form>
);

Edit: Figured it out. The issue was between material-ui@next and material-ui v1.0 they changed checkboxes to use checked for always being checked (based on an initial value), and defaultChecked to be a default value.

3
  • it would be nice if you provide your code in sandbox Commented Jul 28, 2018 at 0:53
  • There's too many dependencies to run this one page that it'd just be easier for you to clone the repo and run it yourself (if you have docker. Instructions for running are in readme.) bitbucket.org/cclloyd9785/opensrd-fullstack/src/master Commented Jul 28, 2018 at 1:11
  • I have answered this question here. Please follow this link. Commented Jan 28, 2019 at 13:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.