Reputation: 1827
I have the following form:
import React from 'react'
import PanelInputField from './form_components/panel_input_field'
import * as yup from 'yup'
import { withFormik, FormikErrors, FormikProps } from "formik";
const validationSchema = yup.object().shape({
length: yup
.number()
.min(200, 'NOT BIG ENOUGH')
.required()
})
class SpecificationsForm extends React.PureComponent {
render() {
const {
values,
handleInputChange,
handleSelectChange,
touched,
errors
} = this.props;
console.log(errors)
return (
<div className="panel panel-default specifications-panel" id="js-turbosquid-product-specifications-panel">
<div className="panel-heading">
<a href="#" className="js-more-info" data-toggle="collapse" data-target="#specifications-panel-instructions" tabIndex="-1">
Specifications
<i className="fa fa-question-circle" />
</a>
</div>
<div className="panel-body panel-collapse collapse in" id="specification-panel-body">
<div className="panel-body-container">
<div id="specifications-panel-instructions" className="panel-instructions collapse" />
<div className="row">
<div className="col-xs-6">
<PanelInputField
label='Length'
value={ values.length }
onChange={ handleInputChange }
formName='turbosquid_product_form_length'
fieldName='length'
/>
<div className="form-field-error">{errors.length ? errors.length : "No Error"}</div>
</div>
</div>
</div>
</div>
)
}
}
const ProductSpecificationsMotionCapturePanel = withFormik({
validationSchema,
enableReinitialize: true,
mapPropsToValues: (props) => (props),
handleInputChange: (props) => (props.handleInputChange),
handleSelectChange: (props) => (props.handleSelectChange),
})(SpecificationsForm)
export default ProductSpecificationsMotionCapturePanel
The form works properly, it is displayed and everything but I can't seem to make formik see the errors. In this example I have the length field with integer values. Whenever I input something, the validations work (the console.log
prints) but the object is totally empty.
Even if I write non numbers in the input, no errors are displayed ever.
Does anyone have a suggestion on what I could do to make it work?
Upvotes: 5
Views: 6393
Reputation: 61
Did you setup initial values? It looks like you did not in this file. If not, try setting that up and see if it works.
Upvotes: 6