jeudi 10 juin 2021

React-Formik-UI checkbox's onChange event not accessible

I am using checkbox from react-formik-ui and it seems I am not able to access the onChange event of this component after I recently updated my react-formik-ui from version 4.0.3 to 5.1.9 and updated formik from version 2.0.8 to 2.2.6.

Implementation of the checkbox:

import {Checkbox} from 'react-formik-ui';

const RenderCheckBox = ({properties}) => {
  return (
    <Fragment key={properties.name}>
      {!properties.isHidden &&
      <FormGroup key={properties.name}>
        <ControlLabel>{properties.label} {properties.required &&
        <span className="required"> * </span>} </ControlLabel>
        <Row>
          {properties.fields.map((element, key) => {
            return (
              <Field key={key} name={element.name}>
                {(props) => {
                  const {onChange: onChangeHandler} = element;
                  const {field, form} = props;
                  return (
                    <Col key={key} className={element.className}>
                      <Checkbox key={key}
                                name={element.name}
                                required={properties.required}
                                disabled={element.isDisabled ? element.isDisabled : false}
                                text={element.label}
                                checked={properties.fields ? properties.fields.find(option => option.value === field.value) : ''}
                                onChange={event => {
                                  console.log("onChange Ran!!")
                                  if (onChangeHandler) {
                                    onChangeHandler(event);
                                  }
                                  form.handleChange(event)
                                }}
                                onBlur={form.handleBlur}
                                value={element.value}
                      />
                    </Col>
                  );
                }}
              </Field>
            )
          })}
        </Row>
      </FormGroup>
      }
    </Fragment>
  )
};

I am not able to run the onChangeHandler through onChange event and even the console log is not coming.




Aucun commentaire:

Enregistrer un commentaire