View difference between Paste ID: g7jhNTjG and mRfgDvN9
SHOW: | | - or go back to the newest paste.
1
import QtQuick 2.0
2
import Sailfish.Silica 1.0
3
4
Page {
5
    id: page
6
7
    property var today: new Date() //todays date
8
    property var usrDate: new Date() //date that the user has picked
9
10
    // Place our content in a Column.  The PageHeader is always placed at the top
11
    // of the page, followed by our content.
12
    Column {
13
        id: column
14
        width: page.width
15
        spacing: Theme.paddingLarge
16
        PageHeader {
17
            title: "Age Calculator"
18
        }
19
20
        Label{ //shows todays date 29/12/2013
21
            text: "Today is: " + today.getFullYear() + " / " + today.getMonth() + " / " + today.getDate()
22
        }
23
24
        Button {
25
            id: button
26
            text: "Choose a date"
27
28
            onClicked: {
29
                var dialog = pageStack.push("Sailfish.Silica.DatePickerDialog", {
30
                                                date: new Date() //uses today date by default 29/12/2013
31
                                            })
32
                dialog.accepted.connect(function() {
33
                    usrDate = dialog
34
                    button.text = "You chose: " + dialog.day
35
                    //console.log("User day: ", usrDate.day)
36-
                console.log("Today's day: ", today.getDate()) //shows 29/12/2013 :)
36+
37-
                console.log("User day: ", dialog.day)       //shows 29/12/2013 :(
37+
             }
38
        }
39-
                usrDate = dialog //trying to copy user picked date to ursDate
39+
40
        Label{ //shows in console: "TypeError: Cannot read property 'year' of null"
41
            text: "User picked: " + usrDate.year + " / " + usrDate.month + " / " + usrDate.day
42
        }
43
44-
        Label{ // does show user picked day :) BUT shows in console: "TypeError: Cannot read property 'year' of null"
44+
        Button { //shows in console: "TypeError: Cannot read property 'year' of null"
45
            id: button2
46
            text: "Test user date"
47
48-
        Button { // does not show user picked date :(, shows in console: "TypeError: Cannot read property 'year' of null"
48+
49
                button2.text = "User picked: " + usrDate.year + " / " + usrDate.month + " / " + usrDate.day
50
            }
51
        }
52
    }
53
}