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) {
|
controlRef(field, wrappedControl) {
|
||||||
if (!wrappedControl) return;
|
if (!wrappedControl) return;
|
||||||
const name = field.get('name');
|
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] =
|
||||||
this.componentValidate[name] = wrappedControl.innerWrappedControl.validate;
|
wrappedControl.innerWrappedControl.validate || wrappedControl.validate;
|
||||||
} else {
|
|
||||||
this.componentValidate[name] = wrappedControl.validate;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
validate = () => {
|
validate = () => {
|
||||||
|
@ -97,7 +97,11 @@ export default class Widget extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
validate = (skipWrapped = false) => {
|
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 errors = [];
|
||||||
const validations = [this.validatePresence, this.validatePattern];
|
const validations = [this.validatePresence, this.validatePattern];
|
||||||
validations.forEach(func => {
|
validations.forEach(func => {
|
||||||
@ -137,9 +141,6 @@ export default class Widget extends Component {
|
|||||||
return { error: false };
|
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)) {
|
if (pattern && !RegExp(pattern.first()).test(value)) {
|
||||||
const error = {
|
const error = {
|
||||||
type: ValidationErrorTypes.PATTERN,
|
type: ValidationErrorTypes.PATTERN,
|
||||||
@ -271,6 +272,7 @@ export default class Widget extends Component {
|
|||||||
getAsset,
|
getAsset,
|
||||||
forID: uniqueFieldId,
|
forID: uniqueFieldId,
|
||||||
ref: this.processInnerControlRef,
|
ref: this.processInnerControlRef,
|
||||||
|
validate: this.validate,
|
||||||
classNameWrapper,
|
classNameWrapper,
|
||||||
classNameWidget,
|
classNameWidget,
|
||||||
classNameWidgetActive,
|
classNameWidgetActive,
|
||||||
|
@ -79,6 +79,7 @@ export default class ListControl extends React.Component {
|
|||||||
onChange: PropTypes.func.isRequired,
|
onChange: PropTypes.func.isRequired,
|
||||||
onChangeObject: PropTypes.func.isRequired,
|
onChangeObject: PropTypes.func.isRequired,
|
||||||
onValidateObject: PropTypes.func.isRequired,
|
onValidateObject: PropTypes.func.isRequired,
|
||||||
|
validate: PropTypes.func.isRequired,
|
||||||
value: ImmutablePropTypes.list,
|
value: ImmutablePropTypes.list,
|
||||||
field: PropTypes.object,
|
field: PropTypes.object,
|
||||||
forID: PropTypes.string,
|
forID: PropTypes.string,
|
||||||
@ -230,9 +231,13 @@ export default class ListControl extends React.Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
validate = () => {
|
validate = () => {
|
||||||
this.validations.forEach(validateListItem => {
|
if (this.getValueType()) {
|
||||||
validateListItem();
|
this.validations.forEach(validateListItem => {
|
||||||
});
|
validateListItem();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.props.validate();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user