[PS-1783] Fix file selector input bug from PS-1465 ( #3502 ) (#3928)

* Fix file selector input

* Add file selector state changes back

* Remove async pipe
This commit is contained in:
Sammy Chang 2022-11-16 10:22:10 -08:00 committed by GitHub
parent fa110a21d0
commit b5e927c2c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -291,11 +291,26 @@
<div class="col-6"> <div class="col-6">
<div class="form-group"> <div class="form-group">
<label for="file">2. {{ "selectImportFile" | i18n }}</label> <label for="file">2. {{ "selectImportFile" | i18n }}</label>
<br />
<div class="file-selector">
<button
type="button"
class="btn btn-outline-primary"
(click)="fileSelector.click()"
[disabled]="importBlockedByPolicy"
>
{{ "chooseFile" | i18n }}
</button>
{{ this.fileSelected ? this.fileSelected.name : ("noFileChosen" | i18n) }}
</div>
<input <input
#fileSelector
type="file" type="file"
id="file" id="file"
class="form-control-file" class="form-control-file"
name="file" name="file"
(change)="setSelectedFile($event)"
hidden
[disabled]="importBlockedByPolicy" [disabled]="importBlockedByPolicy"
/> />
</div> </div>

View File

@ -25,6 +25,7 @@ export class ImportComponent implements OnInit {
importOptions: ImportOption[]; importOptions: ImportOption[];
format: ImportType = null; format: ImportType = null;
fileContents: string; fileContents: string;
fileSelected: File;
formPromise: Promise<ImportError>; formPromise: Promise<ImportError>;
loading = false; loading = false;
importBlockedByPolicy = false; importBlockedByPolicy = false;
@ -179,6 +180,11 @@ export class ImportComponent implements OnInit {
}); });
} }
setSelectedFile(event: Event) {
const fileInputEl = <HTMLInputElement>event.target;
this.fileSelected = fileInputEl.files.length > 0 ? fileInputEl.files[0] : null;
}
private async error(error: Error) { private async error(error: Error) {
await Swal.fire({ await Swal.fire({
heightAuto: false, heightAuto: false,