From b19a3eda1c5583d2bfad26bf7752c162cf9838a7 Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Fri, 23 Dec 2016 10:16:21 +0100 Subject: [PATCH] Added disabled option Resolves #36 --- README.md | 1 + src/select2.component.ts | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/README.md b/README.md index 335867a..14b9e9c 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ Example of `exampleData` can be found [here](https://github.com/NejcZdovc/ng2-se * **value** `string`: Default value for select 2 * **cssImport** `boolean`: Disable or enable default style for select 2, default value is `true` * **width** `string`: Set width for the input, default value is `resolve` +* **disabled** `boolean`: Disable select2, default value is `false` * **options** `Select2Options`: Set options for select 2, [all available options](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/4869992bc079b88280b9ff91213528904109e8ae/select2/index.d.ts#L40) for select 2 ### Outputs diff --git a/src/select2.component.ts b/src/select2.component.ts index 181fd24..cef3e46 100644 --- a/src/select2.component.ts +++ b/src/select2.component.ts @@ -26,6 +26,9 @@ export class Select2Component implements AfterViewInit, OnChanges, OnDestroy, On // width of select2 input @Input() width: string; + // width of select2 input + @Input() disabled: boolean = false; + // all additional options @Input() options: Select2Options; @@ -76,6 +79,10 @@ export class Select2Component implements AfterViewInit, OnChanges, OnDestroy, On value: newValue }); } + + if(changes['disabled'] && changes['disabled'].previousValue !== changes['disabled'].currentValue) { + this.renderer.setElementProperty(this.selector.nativeElement, 'disabled', this.disabled); + } } ngAfterViewInit() { @@ -131,6 +138,10 @@ export class Select2Component implements AfterViewInit, OnChanges, OnDestroy, On } else { this.element.select2(options); } + + if(this.disabled) { + this.renderer.setElementProperty(this.selector.nativeElement, 'disabled', this.disabled); + } } private style: string = `