/** * Base class for form components that provides helper methods * for rendering errors associated with the form **/ class BaseForm extends React.Component { /** * check if the field parameter has errors associated. * if no parameters are given, it checks if there's at least an error at all **/ hasErrors(field) { if ((arguments.length === 0 && this.errorKeys().length > 0) || (this.props.errors && this.props.errors.errors.indexOf(field) > -1)) { return true; } return false; } /** * returns a list of fields that contain errors **/ errorKeys() { return this.props.errors.errors; } /** * returns the type of resource associate with this error **/ errorType() { return this.props.errors.type; } /** * returns the error messages **/ errorMessages() { return this.props.errors.messages; } /** * renders basic form errors **/ renderErrors() { if (!this.hasErrors()) { return null; } var title = "There " + (this.errorMessages().length == 1 ? "is" : "are") + " " + this.errorMessages().length + " error" + (this.errorMessages().length > 1 ? "s" : "") + " for this " + this.errorType() + ":"; var errorMessages = this.errorMessages().map(function(message) { return
  • {message}
  • ; }); return (

    {title}

    ) } }