You've already forked react-forms
Translation support
This commit is contained in:
@@ -8,7 +8,14 @@ export default class FormItemError extends Component
|
||||
if (!data || !data.errors || !data.errors[this.props.name]) return null
|
||||
|
||||
return (
|
||||
<p className="text-danger">{data.errors[this.props.name].error}</p>
|
||||
<FormTranslationConsumer>
|
||||
{(translator) => this.renderError(data, translator)}
|
||||
</FormTranslationConsumer>
|
||||
)
|
||||
}
|
||||
|
||||
renderError(data, translator)
|
||||
{
|
||||
return <p className="text-danger">{translator.handleText(data.errors[this.props.name].error)}</p>
|
||||
}
|
||||
}
|
||||
19
src/FormTranslationContext.js
Normal file
19
src/FormTranslationContext.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import React, { Component } from 'react'
|
||||
|
||||
const FormTranslationContext = React.createContext({
|
||||
renderText: (text) => (text)
|
||||
});
|
||||
|
||||
export default FormTranslationContext
|
||||
|
||||
export class FormTranslationConsumer extends Component
|
||||
{
|
||||
render()
|
||||
{
|
||||
return (
|
||||
<FormTranslationContext.Consumer>
|
||||
{(props) => this.props.children(props)}
|
||||
</FormTranslationContext.Consumer>
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,8 @@ import Radio from './Radio'
|
||||
import RadioGroup from './RadioGroup'
|
||||
import Submit from './Submit'
|
||||
import TextArea from './TextArea'
|
||||
import FormTranslationContext from './FormTranslationContext'
|
||||
|
||||
export {
|
||||
CheckBox, Form, Input, Option, OptionGroup, RadioGroup, Radio, Submit, TextArea
|
||||
CheckBox, Form, Input, Option, OptionGroup, RadioGroup, Radio, Submit, TextArea, FormTranslationContext
|
||||
}
|
||||
Reference in New Issue
Block a user