fix: cleanup nested widget validation (#2991)
* fix: cleanup nested widget validation * fix: list input widget validation
This commit is contained in:
parent
95ba0f5cd0
commit
e4ba4d9d74
@ -17,14 +17,9 @@ export default class ControlPane extends React.Component {
|
||||
controlRef(field, wrappedControl) {
|
||||
if (!wrappedControl) return;
|
||||
const name = field.get('name');
|
||||
const widget = field.get('widget');
|
||||
const listFields = field => field.get('field') || field.get('fields') || field.get('types');
|
||||
|
||||
if ((widget === 'list' && listFields(field)) || widget === 'object') {
|
||||
this.componentValidate[name] = wrappedControl.innerWrappedControl.validate;
|
||||
} else {
|
||||
this.componentValidate[name] = wrappedControl.validate;
|
||||
}
|
||||
this.componentValidate[name] =
|
||||
wrappedControl.innerWrappedControl.validate || wrappedControl.validate;
|
||||
}
|
||||
|
||||
validate = () => {
|
||||
|
@ -97,7 +97,11 @@ export default class Widget extends Component {
|
||||
};
|
||||
|
||||
validate = (skipWrapped = false) => {
|
||||
const { field, value } = this.props;
|
||||
let value = this.props.value;
|
||||
// Convert list input widget value to string for validation test
|
||||
List.isList(value) && (value = value.join(','));
|
||||
|
||||
const field = this.props.field;
|
||||
const errors = [];
|
||||
const validations = [this.validatePresence, this.validatePattern];
|
||||
validations.forEach(func => {
|
||||
@ -137,9 +141,6 @@ export default class Widget extends Component {
|
||||
return { error: false };
|
||||
}
|
||||
|
||||
// Convert list input widget value to string for pattern test
|
||||
List.isList(value) && (value = value.join(','));
|
||||
|
||||
if (pattern && !RegExp(pattern.first()).test(value)) {
|
||||
const error = {
|
||||
type: ValidationErrorTypes.PATTERN,
|
||||
@ -271,6 +272,7 @@ export default class Widget extends Component {
|
||||
getAsset,
|
||||
forID: uniqueFieldId,
|
||||
ref: this.processInnerControlRef,
|
||||
validate: this.validate,
|
||||
classNameWrapper,
|
||||
classNameWidget,
|
||||
classNameWidgetActive,
|
||||
|
@ -79,6 +79,7 @@ export default class ListControl extends React.Component {
|
||||
onChange: PropTypes.func.isRequired,
|
||||
onChangeObject: PropTypes.func.isRequired,
|
||||
onValidateObject: PropTypes.func.isRequired,
|
||||
validate: PropTypes.func.isRequired,
|
||||
value: ImmutablePropTypes.list,
|
||||
field: PropTypes.object,
|
||||
forID: PropTypes.string,
|
||||
@ -230,9 +231,13 @@ export default class ListControl extends React.Component {
|
||||
};
|
||||
|
||||
validate = () => {
|
||||
this.validations.forEach(validateListItem => {
|
||||
validateListItem();
|
||||
});
|
||||
if (this.getValueType()) {
|
||||
this.validations.forEach(validateListItem => {
|
||||
validateListItem();
|
||||
});
|
||||
} else {
|
||||
this.props.validate();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user