2017-08-23 00:19:50 +05:30
|
|
|
import React from 'react';
|
2019-12-07 16:58:52 +05:30
|
|
|
import { MessageDescriptor } from 'react-intl';
|
2016-05-02 14:50:50 +05:30
|
|
|
|
|
|
|
import FormComponent from './FormComponent';
|
2016-07-28 09:55:02 +05:30
|
|
|
import FormError from './FormError';
|
2019-12-08 03:23:22 +05:30
|
|
|
import { ValidationError } from './FormModel';
|
2016-05-02 14:50:50 +05:30
|
|
|
|
2019-12-08 03:23:22 +05:30
|
|
|
type Error = ValidationError | MessageDescriptor;
|
2016-05-02 14:50:50 +05:30
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
export default class FormInputComponent<P, S = {}> extends FormComponent<
|
2019-11-27 14:33:32 +05:30
|
|
|
P & {
|
2019-12-07 16:58:52 +05:30
|
|
|
error?: Error;
|
2019-11-27 14:33:32 +05:30
|
|
|
},
|
|
|
|
S & {
|
2019-12-07 16:58:52 +05:30
|
|
|
error?: Error;
|
|
|
|
}
|
2019-11-27 14:33:32 +05:30
|
|
|
> {
|
|
|
|
componentWillReceiveProps() {
|
|
|
|
if (this.state && this.state.error) {
|
|
|
|
Reflect.deleteProperty(this.state, 'error');
|
2016-05-02 14:50:50 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
this.setState(this.state);
|
2016-05-02 14:50:50 +05:30
|
|
|
}
|
2019-11-27 14:33:32 +05:30
|
|
|
}
|
2016-05-02 14:50:50 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
renderError() {
|
|
|
|
const error = (this.state && this.state.error) || this.props.error;
|
2016-05-02 14:50:50 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
return <FormError error={error} />;
|
|
|
|
}
|
2016-05-02 14:50:50 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
setError(error: Error) {
|
2019-12-07 16:58:52 +05:30
|
|
|
// @ts-ignore
|
2019-11-27 14:33:32 +05:30
|
|
|
this.setState({ error });
|
|
|
|
}
|
2016-05-02 14:50:50 +05:30
|
|
|
}
|