You've already forked react-forms
Fix
This commit is contained in:
28
src/Form.js
28
src/Form.js
@@ -1,8 +1,9 @@
|
||||
import React, {Component, useContext} from 'react';
|
||||
import React, {Component} from 'react';
|
||||
import FormContext from './FormContext';
|
||||
import {toast, ToastContainer} from 'react-toastify';
|
||||
import FormTranslationContext, {FormTranslationConsumer} from './FormTranslationContext'
|
||||
export default class Form extends Component
|
||||
|
||||
class ContextAwareForm extends Component
|
||||
{
|
||||
constructor(props) {
|
||||
super(props)
|
||||
@@ -25,8 +26,7 @@ export default class Form extends Component
|
||||
handleError(props)
|
||||
{
|
||||
if (props.data && props.data.error && props.toast && this.displayError == true) {
|
||||
const contextValue = useContext(FormTranslationContext);
|
||||
toast.error(contextValue.renderText(props.data.error))
|
||||
toast.error(this.props.translator.renderText(props.data.error))
|
||||
this.displayError = false
|
||||
}
|
||||
}
|
||||
@@ -56,11 +56,7 @@ export default class Form extends Component
|
||||
if (this.state.data && this.state.data.error && !this.props.toast)
|
||||
{
|
||||
return (
|
||||
<FormTranslationConsumer>
|
||||
{(translator) => (
|
||||
<p className="alert alert-danger">{translator.renderText(this.state.data.error)}</p>
|
||||
)}
|
||||
</FormTranslationConsumer>
|
||||
<p className="alert alert-danger">{this.props.translator.renderText(this.state.data.error)}</p>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -68,6 +64,20 @@ export default class Form extends Component
|
||||
}
|
||||
}
|
||||
|
||||
export default class Form extends Component
|
||||
{
|
||||
render()
|
||||
{
|
||||
return (
|
||||
<FormTranslationConsumer>
|
||||
{(translator) => (
|
||||
<ContextAwareForm translator={translator} {...this.props}/>
|
||||
)}
|
||||
</FormTranslationConsumer>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Form.defaultProps = {
|
||||
data: null,
|
||||
toast: false,
|
||||
|
||||
Reference in New Issue
Block a user