Odubuc Odubuc - 1 month ago 12
TypeScript Question

NativeScript - TimePicker Cannot get user modified value

I am unable to get the user modified value of a TimePicker. All I'm getting is the original value that I set in the control.

Here is my component template:

<TabView [(ngModel)]="tabSelectedIndex" selectedColor="#FF0000" style="height:90%">
<StackLayout *tabItem="{title: 'Time'}">
<TimePicker #timePicker [(ngModel)]='model.time'></TimePicker>
</StackLayout>
<StackLayout *tabItem="{title: 'Date'}">
<DatePicker #datePicker [(ngModel)]='model.date'></DatePicker>
</StackLayout>
</TabView>
<button text="Done" (tap)="onDoneTap()"></button>


And my component code:

export class DateTimePickerComponent
{
public mDate: Date;
public tabSelectedIndex: number;
public model: any;

constructor()
{
this.mDate = new Date();
this.model = {
date: new Date(2014, 5, 13, 2, 24),
time: new Date(2014, 5, 13, 2, 24)
};
}

private onDoneTap()
{
this.mDate.setMinutes(this.model.time.getMinutes());
this.mDate.setHours(this.model.time.getHours());

this.mDate.setDate(this.model.date.getDate());
this.mDate.setMonth(this.model.date.getMonth());
this.mDate.setFullYear(this.model.date.getFullYear());

console.log(this.mDate);
}
}


To build this I used the Docs:


  • DatePicker - date property

  • TimePicker - time property



In This example the DatePicker works perfectly, it initialise at 2014-05-13 and when I change it, I get the modified value in the console. So am I doing something wrong with the TimePicker ?

Note: I also tried to read the hour and minute property using the ID without success. Always the same initial value (2:24)

@ViewChild("timePicker") timePicker: ElementRef;
let datePickerView = <TimePicker>this.timePicker.nativeElement;
console.log(datePickerView.hour); // 2
console.log(datePickerView.minute) // 24

Answer

For anyone who might fall here:

A bug was opened on Github for this issue. [see here].

Comments