fix: allow widgets to control value to be validated (#3448)

This commit is contained in:
Erez Rokah 2020-03-23 16:33:29 +02:00 committed by GitHub
parent 228c6b41e2
commit ae1917c818
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -97,7 +97,7 @@ export default class Widget extends Component {
};
validate = (skipWrapped = false) => {
let value = this.props.value;
let value = this.innerWrappedControl?.getValidateValue?.() || this.props.value;
// Convert list input widget value to string for validation test
List.isList(value) && (value = value.join(','));

View File

@ -7,6 +7,7 @@ import { once } from 'lodash';
import uuid from 'uuid/v4';
import { oneLine } from 'common-tags';
import { lengths, components, buttons, borders, effects, shadows } from 'netlify-cms-ui-default';
import { basename } from 'netlify-cms-lib-util';
const MAX_DISPLAY_LENGTH = 50;
@ -175,6 +176,14 @@ export default function withFileControl({ forImage } = {}) {
return this.props.onChange('');
};
getValidateValue = () => {
if (this.props.value) {
return basename(this.props.value);
}
return this.props.value;
};
renderFileLink = value => {
const size = MAX_DISPLAY_LENGTH;
if (!value || value.length <= size) {