[ADF-858] added multiple attribute to upload widget (#2064)

This commit is contained in:
Vito 2017-07-07 08:34:54 -07:00 committed by Eugenio Romano
parent af63d2e805
commit c974da301d
3 changed files with 41 additions and 5 deletions

View File

@ -7,6 +7,7 @@
<input *ngIf="!hasFile"
#file
type="file"
[multiple]="multipleOption"
[attr.id]="field.id"
[disabled]="field.readOnly"
class="upload-widget__file"

View File

@ -120,13 +120,12 @@ describe('UploadWidget', () => {
type: FormFieldTypes.UPLOAD,
readOnly: false
});
fixture.detectChanges();
inputElement = <HTMLInputElement>element.querySelector('#upload-id');
});
it('should be disabled on readonly forms', async(() => {
uploadWidget.field.form.readOnly = true;
fixture.detectChanges();
inputElement = <HTMLInputElement>element.querySelector('#upload-id');
fixture.whenStable().then(() => {
fixture.detectChanges();
@ -136,6 +135,32 @@ describe('UploadWidget', () => {
});
}));
it('should have the multiple attribute when is selected in parameters', async(() => {
uploadWidget.field.params.multiple = true;
fixture.detectChanges();
inputElement = <HTMLInputElement>element.querySelector('#upload-id');
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(inputElement).toBeDefined();
expect(inputElement).not.toBeNull();
expect(inputElement.getAttributeNode('multiple')).toBeTruthy();
});
}));
it('should not have the multiple attribute if multiple is false', async(() => {
uploadWidget.field.params.multiple = false;
fixture.detectChanges();
inputElement = <HTMLInputElement>element.querySelector('#upload-id');
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(inputElement).toBeDefined();
expect(inputElement).not.toBeNull();
expect(inputElement.getAttributeNode('multiple')).toBeFalsy();
});
}));
});
});

View File

@ -18,7 +18,7 @@
import { Component, OnInit } from '@angular/core';
import { LogService } from 'ng2-alfresco-core';
import { FormService } from '../../../services/form.service';
import { baseHost , WidgetComponent } from './../widget.component';
import { baseHost, WidgetComponent } from './../widget.component';
@Component({
selector: 'upload-widget',
@ -31,10 +31,11 @@ export class UploadWidget extends WidgetComponent implements OnInit {
hasFile: boolean;
fileName: string;
displayText: string;
multipleOption: string = '';
constructor(public formService: FormService,
private logService: LogService) {
super(formService);
super(formService);
}
ngOnInit() {
@ -46,6 +47,7 @@ export class UploadWidget extends WidgetComponent implements OnInit {
this.fileName = file.name;
this.displayText = decodeURI(file.name);
}
this.getMultipleFileParam();
}
reset() {
@ -74,4 +76,12 @@ export class UploadWidget extends WidgetComponent implements OnInit {
}
}
private getMultipleFileParam() {
if (this.field &&
this.field.params &&
this.field.params.multiple) {
this.multipleOption = this.field.params.multiple ? 'multiple' : '';
}
}
}