Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace file in queue when single select #767

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/file-upload/file-select.directive.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { Directive, ElementRef, Input, HostListener } from '@angular/core';

import { FileUploader } from './file-uploader.class';
import { FileItem } from './file-item.class';

// todo: filters

@Directive({selector: '[ng2FileSelect]'})
export class FileSelectDirective {
@Input() public uploader:FileUploader;

lastFile:FileItem;

protected element:ElementRef;

public constructor(element:ElementRef) {
Expand All @@ -22,7 +25,7 @@ export class FileSelectDirective {
return void 0;
}

public isEmptyAfterSelection():boolean {
public isMultiple():boolean {
return !!this.element.nativeElement.attributes.multiple;
}

Expand All @@ -34,9 +37,16 @@ export class FileSelectDirective {
let filters = this.getFilters();

// if(!this.uploader.isHTML5) this.destroy();

// if not multiple, remove previously added file so we can replace it with the new one
if(!this.isMultiple() && this.lastFile & !this.lastFile.uploaded) this.uploader.removeFromQueue(this.lastFile);

this.uploader.addToQueue(files, options, filters);
if (this.isEmptyAfterSelection()) {

// save file so we can remove it later
this.lastFile = this.uploader.queue[this.uploader.queue.length - 1];

if (this.isMultiple()) {
// todo
this.element.nativeElement.value = '';
/*this.element.nativeElement
Expand Down