@ascentgl/ads-ui 20.0.9 → 20.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -7573,6 +7573,28 @@ class AdsInternationalPhoneFieldComponent extends AbstractInputComponent {
|
|
|
7573
7573
|
/** @ignore */
|
|
7574
7574
|
ngOnInit() {
|
|
7575
7575
|
this.valueControl.addValidators(this.validateMask);
|
|
7576
|
+
if (this.valueControl.disabled) {
|
|
7577
|
+
this.disableControls();
|
|
7578
|
+
}
|
|
7579
|
+
const originalReset = this.valueControl.reset.bind(this.valueControl);
|
|
7580
|
+
this.valueControl.reset = (...args) => {
|
|
7581
|
+
originalReset(...args);
|
|
7582
|
+
this.handleReset();
|
|
7583
|
+
};
|
|
7584
|
+
const originalSetValue = this.valueControl.setValue.bind(this.valueControl);
|
|
7585
|
+
this.valueControl.setValue = ((value, options) => {
|
|
7586
|
+
originalSetValue(value, options);
|
|
7587
|
+
this.handleSetValue(value);
|
|
7588
|
+
});
|
|
7589
|
+
this.valueControl.statusChanges.subscribe((status) => {
|
|
7590
|
+
if (status === 'DISABLED') {
|
|
7591
|
+
this.disableControls();
|
|
7592
|
+
}
|
|
7593
|
+
else {
|
|
7594
|
+
this.dropdownControl.enable({ emitEvent: false });
|
|
7595
|
+
this.inputControl.enable({ emitEvent: false });
|
|
7596
|
+
}
|
|
7597
|
+
});
|
|
7576
7598
|
const value = this.valueControl.value;
|
|
7577
7599
|
if (value && !value.startsWith('+') && /^\d+$/.test(value)) {
|
|
7578
7600
|
this.valueControl.setValue(`+${value}`);
|
|
@@ -7587,7 +7609,26 @@ class AdsInternationalPhoneFieldComponent extends AbstractInputComponent {
|
|
|
7587
7609
|
this.dropdownControl.valueChanges.subscribe(() => this.provideValueToTheValueControl());
|
|
7588
7610
|
}
|
|
7589
7611
|
/** @ignore */
|
|
7590
|
-
|
|
7612
|
+
disableControls() {
|
|
7613
|
+
this.dropdownControl.disable({ emitEvent: false });
|
|
7614
|
+
this.inputControl.disable({ emitEvent: false });
|
|
7615
|
+
}
|
|
7616
|
+
/** @ignore */
|
|
7617
|
+
handleReset() {
|
|
7618
|
+
this.dropdownControl.setValue(this.countryOptions[0], { emitEvent: false });
|
|
7619
|
+
this.inputControl.setValue(null, { emitEvent: false });
|
|
7620
|
+
}
|
|
7621
|
+
/** @ignore */
|
|
7622
|
+
handleSetValue(value) {
|
|
7623
|
+
if (value) {
|
|
7624
|
+
this.parsePhoneNumber(value, false);
|
|
7625
|
+
}
|
|
7626
|
+
else {
|
|
7627
|
+
this.inputControl.setValue(null, { emitEvent: false });
|
|
7628
|
+
}
|
|
7629
|
+
}
|
|
7630
|
+
/** @ignore */
|
|
7631
|
+
parsePhoneNumber(fullNumber, emitEvent = true) {
|
|
7591
7632
|
const trimmed = fullNumber.trim().replace(/\s+/g, ''); // Remove spaces
|
|
7592
7633
|
const knownCodes = ['+52', '+1']; // Add more as needed
|
|
7593
7634
|
knownCodes.sort((a, b) => b.length - a.length); // Match the longest first
|
|
@@ -7597,14 +7638,14 @@ class AdsInternationalPhoneFieldComponent extends AbstractInputComponent {
|
|
|
7597
7638
|
const numberWithoutCode = trimmed.slice(countryCode.length).trim();
|
|
7598
7639
|
switch (countryCode) {
|
|
7599
7640
|
case '+52':
|
|
7600
|
-
this.dropdownControl.setValue(this.countryOptions[1]);
|
|
7601
|
-
this.inputControl.setValue(numberWithoutCode);
|
|
7641
|
+
this.dropdownControl.setValue(this.countryOptions[1], { emitEvent });
|
|
7642
|
+
this.inputControl.setValue(numberWithoutCode, { emitEvent });
|
|
7602
7643
|
break;
|
|
7603
7644
|
case '+1': {
|
|
7604
7645
|
const country = this.getNorthAmericanCountry(fullNumber);
|
|
7605
7646
|
if (country) {
|
|
7606
|
-
this.dropdownControl.setValue(country);
|
|
7607
|
-
this.inputControl.setValue(numberWithoutCode);
|
|
7647
|
+
this.dropdownControl.setValue(country, { emitEvent });
|
|
7648
|
+
this.inputControl.setValue(numberWithoutCode, { emitEvent });
|
|
7608
7649
|
}
|
|
7609
7650
|
break;
|
|
7610
7651
|
}
|