SHOW:
|
|
- or go back to the newest paste.
| 1 | import QtQuick 2.0 | |
| 2 | import Sailfish.Silica 1.0 | |
| 3 | ||
| 4 | ||
| 5 | Dialog {
| |
| 6 | id: inputDialog | |
| 7 | - | canAccept: false |
| 7 | + | canAccept: !title.errorHighlight && !description.errorHighlight |
| 8 | ||
| 9 | property string m_title | |
| 10 | property string m_description | |
| 11 | property string m_date | |
| 12 | ||
| 13 | - | function dialogCanAccept() {
|
| 13 | + | |
| 14 | - | if (date.value.length != 0 && |
| 14 | + | |
| 15 | - | title.text.length != 0 && |
| 15 | + | |
| 16 | - | description.text.length != 0) {
|
| 16 | + | |
| 17 | - | inputDialog.canAccept = true |
| 17 | + | |
| 18 | - | } else {
|
| 18 | + | |
| 19 | - | inputDialog.canAccept = false |
| 19 | + | |
| 20 | label: "Date:" | |
| 21 | value: new Date() | |
| 22 | description: "Default value: ..." | |
| 23 | ||
| 24 | onClicked: {
| |
| 25 | var dialog = pageStack.push(pickerComponent, {
| |
| 26 | date: new Date() | |
| 27 | }) | |
| 28 | dialog.accepted.connect(function() {
| |
| 29 | date.value = dialog.dateText | |
| 30 | }) | |
| 31 | } | |
| 32 | ||
| 33 | Component {
| |
| 34 | id: pickerComponent | |
| 35 | DatePickerDialog {}
| |
| 36 | } | |
| 37 | } | |
| 38 | ||
| 39 | TextField {
| |
| 40 | id: title | |
| 41 | width: inputDialog.width | |
| 42 | placeholderText: qsTr("Enter title")
| |
| 43 | description: qsTr("Title")
| |
| 44 | errorHighlight: text.length == 0 | |
| 45 | EnterKey.enabled: text || inputMethodComposing | |
| 46 | EnterKey.iconSource: "image://theme/icon-m-enter-next" | |
| 47 | EnterKey.onClicked: description.focus = true | |
| 48 | } | |
| 49 | ||
| 50 | TextField {
| |
| 51 | id: description | |
| 52 | width: inputDialog.width | |
| 53 | - | onTextChanged: dialogCanAccept() |
| 53 | + | |
| 54 | description: qsTr("Description")
| |
| 55 | errorHighlight: text.length == 0 | |
| 56 | EnterKey.enabled: text || inputMethodComposing | |
| 57 | EnterKey.highlighted: !errorHighlight | |
| 58 | EnterKey.iconSource: "image://theme/icon-m-enter-next" | |
| 59 | EnterKey.onClicked: {
| |
| 60 | - | onTextChanged: dialogCanAccept() |
| 60 | + | if (!inputDialog.canAccept) |
| 61 | title.focus = true | |
| 62 | else | |
| 63 | inputDialog.accept() | |
| 64 | } | |
| 65 | } | |
| 66 | } | |
| 67 | ||
| 68 | onDone: {
| |
| 69 | if (result == DialogResult.Accepted) {
| |
| 70 | m_title = title.text | |
| 71 | console.log(m_title) | |
| 72 | m_description = description.text | |
| 73 | console.log(m_description) | |
| 74 | m_date = date.value | |
| 75 | console.log(m_date) | |
| 76 | } | |
| 77 | } | |
| 78 | } |