Skip to content

Commit 0075ddf

Browse files
committed
Fix #15: Allow clearing a file field
1 parent 6bb7ac6 commit 0075ddf

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/components/form.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,18 @@ export class FormFileInput extends React.Component {
272272
this.inputRef.current.click();
273273
}
274274

275+
clearFile = () => {
276+
let event = {
277+
target: {
278+
type: 'text',
279+
value: '',
280+
name: this.props.name
281+
}
282+
};
283+
284+
this.props.onChange(event);
285+
}
286+
275287
render() {
276288
let {label, value, ...props} = {value, ...this.props};
277289
props.type = 'file';
@@ -280,13 +292,15 @@ export class FormFileInput extends React.Component {
280292
if (props.readOnly)
281293
props.disabled = true;
282294

283-
284295
return (
285-
<div>
296+
<div>
286297
{label && <label>{label}</label>}
287298
<div className="rjf-file-field">
288299
{this.state.value &&
289-
<div className="rjf-current-file-name">Current file: <span>{this.state.fileName}</span></div>
300+
<div className="rjf-current-file-name">
301+
Current file: <span>{this.state.fileName}</span> {' '}
302+
<Button className="remove-file" onClick={this.clearFile}>Clear</Button>
303+
</div>
290304
}
291305
{this.state.value && !this.state.loading && 'Change:'}
292306
{this.state.loading ?

0 commit comments

Comments
 (0)