Skip to content

Commit

Permalink
[core] fileElement multitype value fix (#7381)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
laemtl authored Mar 29, 2021
1 parent 4c8fabe commit 717f5b2
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion jsx/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 717f5b2

Please # to comment.