Skip to content
This repository has been archived by the owner on Oct 5, 2019. It is now read-only.

fix readonly and required attributes #182

Open
wants to merge 2 commits into
base: master
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
17 changes: 13 additions & 4 deletions src/ng2-datetime/ng2-datetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ const CUSTOM_ACCESSOR = {
multi: true
};

declare var jQuery : any;
declare var $ : any;

@Component({
selector: 'datetime',
providers: [CUSTOM_ACCESSOR],
template: `
<div class="ng2-datetime">
<div [ngClass]="{ 'input-group': !datepickerOptions.hideIcon, 'date': true }">
<input id="{{idDatePicker}}" type="text" class="form-control"
[attr.readonly]="readonly"
[attr.required]="required"
[attr.readonly]="readonly || null"
[attr.required]="required || null"
[attr.placeholder]="datepickerOptions.placeholder || 'Choose date'"
[attr.tabindex]="tabindex"
[(ngModel)]="dateModel"
Expand All @@ -33,8 +36,8 @@ const CUSTOM_ACCESSOR = {
</div>
<div [ngClass]="{ 'input-group': !timepickerOptions.hideIcon, 'bootstrap-timepicker timepicker': true }">
<input id="{{idTimePicker}}" type="text" class="form-control input-small"
[attr.readonly]="readonly"
[attr.required]="required"
[attr.readonly]="readonly || null"
[attr.required]="required || null"
[attr.placeholder]="timepickerOptions.placeholder || 'Set time'"
[attr.tabindex]="tabindex"
[(ngModel)]="timeModel"
Expand Down Expand Up @@ -119,6 +122,12 @@ export class NKDatetime implements ControlValueAccessor, AfterViewInit, OnDestro
this.timepicker.parent().remove();
}
}

if (changes['readonly'] && this.datepicker) {
this.datepicker.datepicker('destroy');
this.datepicker = null;
this.init();
}
}
}

Expand Down