forked from microsoft/AdaptiveCards
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathTextInputRender.qml
More file actions
125 lines (98 loc) · 3.68 KB
/
TextInputRender.qml
File metadata and controls
125 lines (98 loc) · 3.68 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import QtQuick 2.15
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.15
import AdaptiveCardQmlEngine 1.0
import "JSUtils/AdaptiveCardUtils.js" as AdaptiveCardUtils
Column {
id: inputText
property var cardConst: CardConstants
property var textInputModel: model.textInputRole
property string submitValue: !textInputModel.isMultiLineText ? singlineLoaderElement.item.textValue : multilineLoaderElement.item.textValue
property bool showErrorMessage: false
function validate() {
const regex = new RegExp(textInputModel.regex);
let isValid = true;
if (textInputModel.isRequired)
isValid = (submitValue !== '' && regex.test(submitValue));
else if (submitValue !== '')
isValid = regex.test(submitValue);
if (showErrorMessage && isValid)
showErrorMessage = false;
return !isValid;
}
function getAccessibleName() {
let accessibleName = '';
if (showErrorMessage === true)
accessibleName += "Error" + textInputModel.errorMessage;
accessibleName += textInputModel.label;
if (submitValue !== '')
accessibleName += (submitValue + '. ');
else
accessibleName += textInputModel.placeholder;
accessibleName += qsTr(", Type the text");
return accessibleName;
}
visible: textInputModel.isVisible
spacing: textInputModel.spacing
width: parent.width
onActiveFocusChanged: {
if (activeFocus)
nextItemInFocusChain().forceActiveFocus();
}
onSubmitValueChanged: {
if (textInputModel.isRequired || textInputModel.regex != "")
validate();
}
onShowErrorMessageChanged: {
if (textInputModel.heightStreched && textInputModel.isMultiLineText) {
if (showErrorMessage)
inputtextTextFieldRow.height = inputtextTextFieldRow.height - inputtextErrorMessage.height;
else
inputtextTextFieldRow.height = inputtextTextFieldRow.height + inputtextErrorMessage.height;
}
}
InputLabel {
id: inputTextLabel
label: textInputModel.label
required: textInputModel.isRequired
visible: textInputModel.label
}
Row {
id: inputtextTextFieldRow
function getStrechHeight() {
if (textInputModel.heightStreched && textInputModel.isMultiLineText)
return parent.height > 0 ? parent.height - y : cardConst.inputTextConstants.multiLineTextHeight;
}
spacing: 5
width: parent.width
height: implicitHeight
Loader {
id: singlineLoaderElement
height: 30
width: parent.width
active: !textInputModel.isMultiLineText
visible: !textInputModel.isMultiLineText
sourceComponent: SingleLineTextInputRender {
id: inputtextTextFieldWrapper
errorMessageVisible: showErrorMessage
}
}
Loader {
id: multilineLoaderElement
height: 100
width: parent.width
active: textInputModel.isMultiLineText
visible: textInputModel.isMultiLineText
sourceComponent: MultiLineTextInputRender {
id: inputtextTextFieldWrapper
errorMessageVisible: showErrorMessage
height: textInputModel.heightStreched ? parent.height : cardConst.inputTextConstants.multiLineTextHeight
}
}
}
InputErrorMessage {
id: inputtextErrorMessage
isErrorMessage: textInputModel.errorMessage
visible: showErrorMessage
}
}