Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Developer
mattw13
Posts: 6
Registered: ‎03-03-2014
My Device: BlackBerry Z10
Accepted Solution

Trouble setting Time in DateTimePicker

Hi All,

 

Totally new to BB10 Cascades development here, so forgive any ignorance.

I'm setting up an app in which a user can select days of the week via check box, and then corresponding start time and end times for those days using DateTimePickers for each start and stop time.

What I'm trying to do is set the Time value when the user selects a predefined setting from a dropdown.

In this case, I've got some hard coded values for a default profile, so what I want is to be able to select the profile from the dropdown, and then have the days of the week checked and the time values that I want adjusted in the DateTimePickers.

I'm having no trouble getting the check boxes to trigger, but for the life of me, I can't get the value of the DateTimePickers to change or update.

I'm creating the DateTimePickers in qml using the following code:

 

DateTimePicker {
id: monday_start
mode: DateTimePickerMode.Time
value: {new Date();}

}

 

I've been scouring the web trying to figure this out, but I'm not having any luck.

Are there any really good examples of how to manipulate the DateTimePicker values out there that would make sense to a "newb".

I appreciate the help.

 

Developer
BBSJdev
Posts: 6,116
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: Trouble setting Time in DateTimePicker

Have you looked at the eaxmples given here?

 

http://developer.blackberry.com/native/documentation/cascades/ui/pickers/datetimepicker.html


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
New Developer
mattw13
Posts: 6
Registered: ‎03-03-2014
My Device: BlackBerry Z10

Re: Trouble setting Time in DateTimePicker

Thanks for the reply.

I've reviewed the examples, but I can't figure out which function I should be using to update the control value.

I've tried:

 

datepicker.value()

datepicker.datetimefrom()

datepicker.value.setHour() and datepicker.value.setMinutes()

 

but what I'm seeing when I try any of these on the dropdown onSelectedValueChanged () trigger is that the check boxes that I have select as I've requested, but the time values won't change.

Is there some form of update or refresh function that I should be calling after I set the value for the datepicker?

 

Thanks again.

Developer
BBSJdev
Posts: 6,116
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: Trouble setting Time in DateTimePicker

No nothing like that, can you post the code you've got so far?

If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Developer
BBSJdev
Posts: 6,116
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: Trouble setting Time in DateTimePicker

Setting the value like this works for me without having to register a QDateTime class...

 

	        DateTimePicker {
	            id: pickerTime
	            title: "Time"
	            mode: DateTimePickerMode.Time
	            value: pickerTime.dateFromTime("10:11:00")
	        }

            Button {
                text: "Set Current DateTime"
                onClicked: {
                    var d = new Date();
                    var f = pickerTime.value;
                    f.setHours(d.getHours());
                    f.setMinutes(d.getMinutes());
                    f.setSeconds(d.getSeconds());
                    pickerTime.value = f;
                }
            }

 


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
New Developer
mattw13
Posts: 6
Registered: ‎03-03-2014
My Device: BlackBerry Z10

Re: Trouble setting Time in DateTimePicker

That seems to have worked on my end as well.

I thought that's what I was doing with my setHours, and setMinutes, but I was just trying to work directly with the control instead of creating the variable and putting the value into the control.

Rookie move!  I've been out of the coding scene for 10+ years, so jumping back into this is a much steeper learnig curve than I had hoped.

Thank you so much for the help!