question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CheckboxWithLabel- Yup

See original GitHub issue

Hi, The label does not appear, nor the error message … I need help please please

import React from 'react'
import { Formik, Field, Form } from 'formik'
import { TextField, CheckboxWithLabel } from 'formik-material-ui'
import * as Yup from 'yup'

const SignupForm = () => {
  return (
<Formik
      initialValues={{ accept: false }}
      validationSchema={Yup.object({
        accept: Yup.boolean()
          .required('Requis')
          .oneOf([true], "Error")
      })}

<Form>
        <Field
          name='accept'
          label='condition'
          type='checkbox'
          component={CheckboxWithLabel}
        />
</Form>
</Formik>
  )
}

export default SignupForm

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
wichertcommented, Apr 21, 2020

I ended up doing this:

const tosError = formikBag.getFieldMeta('acceptTos').error

return (
  <Field
    component={CheckboxWithLabel}
    type="checkbox"
    name="acceptTos"
    Label={{ label: "I accept the terms and conditions" }}
    color="primary"
  />
  {tosError ? <FormHelperText error>{tosError}</FormHelperText>:null}
)
3reactions
mjdealecommented, Jan 24, 2020

@vegtelenseg @Jippay @cliedeman:

The solution above is NOT using the CheckboxWithLabel code to put the label up. It is simply wrapping a label around a CheckboxWithLabel that failed to put a label up, using the FormControlLabel functionality.

I believe the confusion is caused because the sample code in the API documentation is wrong. It shows:

<CheckboxWithLabel name="checked" label="Checkbox" />

^^^^^ which doesn’t work.

What does work is:

<CheckboxWithLabel name="checked" Label={{ label: "Checkbox" }} />

I am not sure if the right thing to do is to change the CheckboxWithLabel component, or the documentation, but clearly changing the documentation would clear up the confusion that exists right now.

– M

Read more comments on GitHub >

github_iconTop Results From Across the Web

CheckboxWithLabel- Yup · Issue #120 · stackworx/formik-mui
It is simply wrapping a label around a CheckboxWithLabel that failed to put a label up, using the FormControlLabel functionality. I believe the ......
Read more >
formik-material-ui checkboxes - CodeSandbox
CodeSandbox is an online editor tailored for web applications.
Read more >
Handling Multiple Checkboxes with Material UI and Formik
I have a form with a checkbox group containing 4 checkboxes within. I need to pass the value to my api on submit...
Read more >
Checkboxes Example - Formik
This example demonstrates how to use Formik with a checkbox group. Given that the fields all share the same `name`, Formik will automagically...
Read more >
Checkbox Field - Formik for Beginners - Code Daily
Following up with errors and validation. Then we'll dive into building a login form and a registration form, and end the course with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found