Skip to content

Commit 3d23383

Browse files
committed
more refactoring
1 parent dcd49ff commit 3d23383

File tree

1 file changed

+26
-20
lines changed
  • services/static-webserver/client/source/class/osparc/ui/form

1 file changed

+26
-20
lines changed

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

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,11 @@ qx.Class.define("osparc.ui.form.IntlTelInput", {
3636
});
3737

3838
const randId = Math.floor(Math.random() * 100);
39-
const html = `<input type='tel' id='phone-${randId}' name='phone' autocomplete='off'>`;
39+
this.__htmlId = `phone-${randId}`;
40+
const html = `<input type='tel' id='${this.__htmlId}' name='phone' autocomplete='off'>`;
4041
const phoneNumber = this.getChildControl("phone-input-field");
4142
phoneNumber.setHtml(html);
42-
phoneNumber.addListenerOnce("appear", () => {
43-
const convertInputToPhoneInput = () => {
44-
const domElement = document.querySelector(`#phone-${randId}`);
45-
this.__itiInput = this.__inputToPhoneInput(domElement);
46-
phoneNumber.getContentElement().setStyles({
47-
"overflow": "visible" // needed for countries dropdown menu
48-
});
49-
};
50-
const intlTelInputLib = osparc.wrapper.IntlTelInput.getInstance();
51-
if (intlTelInputLib.getLibReady()) {
52-
convertInputToPhoneInput();
53-
} else {
54-
intlTelInputLib.addListenerOnce("changeLibReady", e => {
55-
if (e.getData()) {
56-
convertInputToPhoneInput();
57-
}
58-
});
59-
}
60-
});
43+
phoneNumber.addListenerOnce("appear", () => this.__convertInputToPhoneInput(), this);
6144
},
6245

6346
properties: {
@@ -86,6 +69,7 @@ qx.Class.define("osparc.ui.form.IntlTelInput", {
8669
},
8770

8871
members: {
72+
__htmlId: null,
8973
__itiInput: null,
9074

9175
_createChildControlImpl: function(id) {
@@ -159,6 +143,28 @@ qx.Class.define("osparc.ui.form.IntlTelInput", {
159143
this.self().updateStyle(this.__itiInput, feedbackIcon);
160144
},
161145

146+
__convertInputToPhoneInput: function() {
147+
const convertInputToPhoneInput = () => {
148+
const domElement = document.querySelector(`#${this.__htmlId}`);
149+
const phoneNumber = this.getChildControl("phone-input-field");
150+
this.__itiInput = this.__inputToPhoneInput(domElement);
151+
phoneNumber.getContentElement().setStyles({
152+
"overflow": "visible" // needed for countries dropdown menu
153+
});
154+
};
155+
156+
const intlTelInputLib = osparc.wrapper.IntlTelInput.getInstance();
157+
if (intlTelInputLib.getLibReady()) {
158+
convertInputToPhoneInput();
159+
} else {
160+
intlTelInputLib.addListenerOnce("changeLibReady", e => {
161+
if (e.getData()) {
162+
convertInputToPhoneInput();
163+
}
164+
});
165+
}
166+
},
167+
162168
__inputToPhoneInput: function(input) {
163169
const iti = intlTelInput(input, {
164170
initialCountry: "auto",

0 commit comments

Comments
 (0)