enhancement: improve error with no existing widget (#2722)

* enhancement: improve error with no existing widget

* Update Widget.js

* chore: fix formatting of Widget.js
This commit is contained in:
polemius 2019-10-24 10:59:32 +02:00 committed by Erez Rokah
parent e09edd554f
commit 7ca528b20a

View File

@ -2,6 +2,7 @@ import PropTypes from 'prop-types';
import React, { Component } from 'react'; import React, { Component } from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes'; import ImmutablePropTypes from 'react-immutable-proptypes';
import { Map, List } from 'immutable'; import { Map, List } from 'immutable';
import { oneLine } from 'common-tags';
import ValidationErrorTypes from 'Constants/validationErrorTypes'; import ValidationErrorTypes from 'Constants/validationErrorTypes';
const truthy = () => ({ error: false }); const truthy = () => ({ error: false });
@ -153,6 +154,13 @@ export default class Widget extends Component {
validateWrappedControl = field => { validateWrappedControl = field => {
const t = this.props.t; const t = this.props.t;
if (typeof this.wrappedControlValid !== 'function') {
throw new Error(oneLine`
this.wrappedControlValid is not a function. Are you sure widget
"${field.get('widget')}" is registered?
`);
}
const response = this.wrappedControlValid(); const response = this.wrappedControlValid();
if (typeof response === 'boolean') { if (typeof response === 'boolean') {
const isValid = response; const isValid = response;