I am having difficulty overwriting the default error message in redux-form-validators
using the code suggested by the docs:
Object.assign(Validators.messages, {
required: "This is a required field"
})
This gives an error
Validators is not defined
Problem: What is this Validators
object and where/how should we define/use it so that we can overwrite the default messages properly?
/containers/Animals/Animals.js
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { reduxForm, Field } from 'redux-form';
import { required } from 'redux-form-validators';
import { renderTextField } from './FormHelpers';
class AnimalForm extends Component {
constructor(props) {
super(props);
Object.assign(Validators.messages, { // ERROR OCCURS HERE
required: "This is a required field"
})
}
render() {
return (
<div>
<form>
<Field
label="Longitude"
name="location.coordinates[0]"
component={renderTextField}
type="text"
validate={[required()]}
/>
</form>
</div>
)
}
}
export default connect(mapStateToProps)(reduxForm({
form: 'animal'
})(AnimalForm))
Try adding Validators to your import