-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFForm.qml
97 lines (84 loc) · 2.13 KB
/
FForm.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import QtQuick 2.3
FocusScope {
id: _root
property bool _FORM_TYPE_FORM: true
property var validator: null
signal accepted()
signal rejected()
signal submitted()
function resetFocus() {
_focusFirstInput(this)
}
function checkInput(element) {
var ok = true
for (var i = 0; i < element.children.length; ++i)
{
var child = element.children[i]
if (!child._FORM_TYPE_IGNORE_IN_FORM_VALIDATION)
{
if (child._FORM_TYPE_ACCEPTABLE)
{
if (!child.acceptableInput)
{
ok = false
}
}
ok = ok && checkInput(child)
}
}
return ok
}
onSubmitted: {
var accept = false
if (validator)
{
if (validator() && checkInput(this)) accept = true
}
else
{
if (checkInput(this)) accept = true
}
if (accept) accepted()
else rejected()
}
function submit() {
submitted()
}
Keys.onReturnPressed: submitted()
Keys.onEnterPressed: submitted()
function clear()
{
clearElement(this)
}
function clearElement(element)
{
for (var i = 0; i < element.children.length; ++i)
{
var child = element.children[i]
if (!child._FORM_TYPE_IGNORE_IN_FORM_CLEARING)
{
if (child._FORM_TYPE_INPUT_TEXT)
{
child.text = ""
}
clearElement(child)
}
}
}
function _focusFirstInput(element)
{
var found = false
for (var i = 0; i < element.children.length && found == false; ++i)
{
var child = element.children[i]
if (child._FORM_TYPE_INPUT)
{
child.focus = true
found = true
}
found = found || _focusFirstInput(child)
}
return found
}
Component.onCompleted: _focusFirstInput(this)
}