From 717f5b2123a8c083e92dc0398f45bf69202ab975 Mon Sep 17 00:00:00 2001 From: Laetitia Fesselier Date: Mon, 29 Mar 2021 14:12:33 -0400 Subject: [PATCH] [core] fileElement multitype value fix (#7381) The value props of a fileElement can be of type string or Object, but the assignment to filename only covers the object case. As a result, in media, if we edit a file, the fileElement does not display the file name. This aims to fix this. --- jsx/Form.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/jsx/Form.js b/jsx/Form.js index 24ac5ec6982..dd7feb54c3c 100644 --- a/jsx/Form.js +++ b/jsx/Form.js @@ -1553,7 +1553,23 @@ class FileElement extends Component { */ render() { const required = this.props.required ? 'required' : null; - const fileName = this.props.value ? this.props.value.name : undefined; + + let fileName = undefined; + if (this.props.value) { + switch (typeof this.props.value) { + case 'string': + fileName = this.props.value; + break; + + case 'object': + fileName = this.props.value.name; + break; + + default: + break; + } + } + let requiredHTML = null; let errorMessage = ''; let elementClass = 'row form-group';