Skip to content

Commit

Permalink
Added disabled option
Browse files Browse the repository at this point in the history
Resolves #36
  • Loading branch information
NejcZdovc committed Dec 23, 2016
1 parent e42e89a commit b19a3ed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/select2.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export class Select2Component implements AfterViewInit, OnChanges, OnDestroy, On
// width of select2 input
@Input() width: string;

// width of select2 input

This comment has been minimized.

Copy link
@fjozsef

fjozsef Dec 23, 2016

Contributor

I think this comment shouldn't be here.

This comment has been minimized.

Copy link
@NejcZdovc

NejcZdovc Dec 23, 2016

Author Owner

Correct 😄

@Input() disabled: boolean = false;

// all additional options
@Input() options: Select2Options;

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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 = `
Expand Down

0 comments on commit b19a3ed

Please # to comment.