Skip to content

Commit dcd49ff

Browse files
committed
refactor
1 parent e2ba8a7 commit dcd49ff

File tree

1 file changed

+28
-18
lines changed
  • services/static-webserver/client/source/class/osparc/ui/form

1 file changed

+28
-18
lines changed

services/static-webserver/client/source/class/osparc/ui/form/IntlTelInput.js

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,8 @@ qx.Class.define("osparc.ui.form.IntlTelInput", {
3737

3838
const randId = Math.floor(Math.random() * 100);
3939
const html = `<input type='tel' id='phone-${randId}' name='phone' autocomplete='off'>`;
40-
const phoneNumber = new qx.ui.embed.Html(html).set({
41-
marginTop: 2,
42-
marginLeft: 2,
43-
marginRight: 2,
44-
minWidth: 185,
45-
maxHeight: 25
46-
});
47-
this._add(phoneNumber);
40+
const phoneNumber = this.getChildControl("phone-input-field");
41+
phoneNumber.setHtml(html);
4842
phoneNumber.addListenerOnce("appear", () => {
4943
const convertInputToPhoneInput = () => {
5044
const domElement = document.querySelector(`#phone-${randId}`);
@@ -64,10 +58,6 @@ qx.Class.define("osparc.ui.form.IntlTelInput", {
6458
});
6559
}
6660
});
67-
68-
const feedbackCheck = this.__feedbackCheck = new qx.ui.basic.Image();
69-
feedbackCheck.exclude();
70-
this._add(feedbackCheck);
7161
},
7262

7363
properties: {
@@ -97,7 +87,27 @@ qx.Class.define("osparc.ui.form.IntlTelInput", {
9787

9888
members: {
9989
__itiInput: null,
100-
__feedbackCheck: null,
90+
91+
_createChildControlImpl: function(id) {
92+
let control;
93+
switch (id) {
94+
case "phone-input-field":
95+
control = new qx.ui.embed.Html().set({
96+
marginTop: 2,
97+
marginLeft: 2,
98+
marginRight: 2,
99+
minWidth: 185,
100+
maxHeight: 25
101+
});
102+
this._add(control, { flex: 1 });
103+
break;
104+
case "feedback-icon":
105+
control = new qx.ui.basic.Image();
106+
this._add(control);
107+
break
108+
}
109+
return control || this.base(arguments, id);
110+
},
101111

102112
// IStringForm interface implementation
103113
getValue: function() {
@@ -125,14 +135,14 @@ qx.Class.define("osparc.ui.form.IntlTelInput", {
125135
},
126136

127137
verifyPhoneNumber: function() {
138+
const feedbackIcon = this.getChildControl("feedback-icon");
128139
const isValid = this.isValidNumber();
129-
this.__feedbackCheck.set({
140+
feedbackIcon.set({
130141
toolTipText: "E.164: " + this.getValue(),
131142
source: isValid ? "@FontAwesome5Solid/check/16" : "@FontAwesome5Solid/exclamation-triangle/16",
132143
textColor: isValid ? "text" : "failed-red",
133144
alignY: "middle",
134145
});
135-
this.__feedbackCheck.show();
136146
if (!isValid) {
137147
const validationError = this.__itiInput.getValidationError();
138148
const errorMap = {
@@ -142,11 +152,11 @@ qx.Class.define("osparc.ui.form.IntlTelInput", {
142152
3: this.tr("Number too long")
143153
};
144154
const errorMsg = errorMap[validationError] || "Invalid number";
145-
this.__feedbackCheck.set({
146-
toolTipText: errorMsg + ". " + this.__feedbackCheck.getToolTipText()
155+
feedbackIcon.set({
156+
toolTipText: errorMsg + ". " + feedbackIcon.getToolTipText()
147157
});
148158
}
149-
this.self().updateStyle(this.__itiInput, this.__feedbackCheck);
159+
this.self().updateStyle(this.__itiInput, feedbackIcon);
150160
},
151161

152162
__inputToPhoneInput: function(input) {

0 commit comments

Comments
 (0)