Display selected file name when re-selected after clear

Refs #812
This commit is contained in:
Will Abson 2016-11-17 11:42:13 +00:00 committed by Mario Romano
parent f64ef77d41
commit 1c2b2fa40a
3 changed files with 11 additions and 13 deletions

View File

@ -2,7 +2,7 @@
<label [attr.for]="field.id">{{field.name}}</label>
<div>
<span *ngIf="hasFile" class="attach-widget__file">{{getLinkedFileName()}}</span>
<span *ngIf="hasFile()" class="attach-widget__file mdl-chip"><span class="mdl-chip__text">{{getLinkedFileName()}}</span></span>
<button #browseFile (click)="showDialog();" class="mdl-button mdl-js-button mdl-js-ripple-effect attach-widget__browser">
<i class="material-icons">image</i>
Browse {{selectedFolderSiteName}}

View File

@ -42,24 +42,23 @@ describe('AttachWidget', () => {
});
it('should require field value to check file', () => {
widget.hasFile = false;
widget.field = null;
widget.ngOnInit();
expect(widget.hasFile).toBeFalsy();
expect(widget.hasFile()).toBeFalsy();
widget.field = new FormFieldModel(null, {
type: FormFieldTypes.UPLOAD,
value: null
});
widget.ngOnInit();
expect(widget.hasFile).toBeFalsy();
expect(widget.hasFile()).toBeFalsy();
widget.field = new FormFieldModel(null, {
type: FormFieldTypes.UPLOAD,
value: [{ name: 'file' }]
});
widget.ngOnInit();
expect(widget.hasFile).toBeTruthy();
expect(widget.hasFile()).toBeTruthy();
});
it('should setup with form field', () => {
@ -116,19 +115,20 @@ describe('AttachWidget', () => {
expect(widget.selectedFile).toBe(node);
expect(widget.field.value).toEqual([link]);
expect(widget.field.json.value).toEqual([link]);
expect(widget.hasFile()).toBeTruthy();
});
it('should reset', () => {
widget.hasFile = true;
widget.field = new FormFieldModel(null, {
type: FormFieldTypes.UPLOAD,
value: [{ name: 'filename' }]
});
widget.reset();
expect(widget.hasFile).toBeFalsy();
expect(widget.hasFile()).toBeFalsy();
expect(widget.field.value).toBeNull();
expect(widget.field.json.value).toBeNull();
expect(widget.hasFile()).toBeFalsy();
});
it('should close dialog on cancel', () => {

View File

@ -35,7 +35,6 @@ export class AttachWidget extends WidgetComponent implements OnInit {
selectedFolderSiteName: string;
selectedFolderAccountId: string;
fileName: string;
hasFile: boolean;
selectedFolderNodes: [ExternalContent];
selectedFile: ExternalContent;
@ -54,10 +53,6 @@ export class AttachWidget extends WidgetComponent implements OnInit {
ngOnInit() {
if (this.field) {
if (this.field.value) {
this.hasFile = true;
}
let params = this.field.params;
if (params &&
@ -149,7 +144,10 @@ export class AttachWidget extends WidgetComponent implements OnInit {
reset() {
this.field.value = null;
this.field.json.value = null;
this.hasFile = false;
}
hasFile(): boolean {
return this.field && this.field.value;
}
}