monkey-style-guide-v2 0.0.65 → 0.0.67

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.
@@ -5650,7 +5650,7 @@ class MonkeyInputPhoneComponent {
5650
5650
  getCountryByCallingCode(code) {
5651
5651
  const cleanCode = code.replace('+', '');
5652
5652
  return (getCountries().find((country) => {
5653
- return getCountryCallingCode(country) === cleanCode || country === code;
5653
+ return country === cleanCode;
5654
5654
  }) || null);
5655
5655
  }
5656
5656
  isoToFlagEmoji(isoCode) {
@@ -5672,23 +5672,23 @@ class MonkeyInputPhoneComponent {
5672
5672
  return this.selectedCallingCode;
5673
5673
  }
5674
5674
  performValue(value) {
5675
- this._value = `${this.selectedCallingCode}${value}`;
5675
+ const countryCode = `+${getCountryCallingCode(this.selectedCallingCode)}`;
5676
+ this._value = `${countryCode}${value}`;
5676
5677
  this._onChange(this._value);
5677
5678
  this._onTouched(this._value);
5678
5679
  }
5679
5680
  validateValue() {
5680
5681
  const { phoneValid } = this;
5681
5682
  if (!phoneValid) {
5682
- const countryCode = this.getCountryByCallingCode(this.selectedCallingCode);
5683
+ const countryCode = this.selectedCallingCode;
5683
5684
  const example = getExampleNumber(countryCode, examples);
5685
+ const formatter = new AsYouType(countryCode);
5686
+ const phoneAllowed = formatter.input(example.nationalNumber);
5684
5687
  this.ngControl?.control?.setErrors({
5685
5688
  phone: true,
5686
- phoneAllowed: example?.nationalNumber
5689
+ phoneAllowed
5687
5690
  });
5688
5691
  }
5689
- else {
5690
- this.ngControl?.control?.setErrors(null);
5691
- }
5692
5692
  }
5693
5693
  formatValue(value, changedCountry = false) {
5694
5694
  if (!value) {
@@ -5702,18 +5702,19 @@ class MonkeyInputPhoneComponent {
5702
5702
  if (isCountryChanged && detectedCallingCode) {
5703
5703
  this.selectedCallingCode = detectedCallingCode;
5704
5704
  }
5705
- const countryCode = this.getCountryByCallingCode(this.selectedCallingCode);
5705
+ const countryCode = `+${getCountryCallingCode(this.selectedCallingCode)}`;
5706
5706
  if (!countryCode) {
5707
5707
  this.phoneFormatted = value;
5708
5708
  this.phoneValid = false;
5709
5709
  this.validateValue();
5710
5710
  return;
5711
5711
  }
5712
- const nationalPart = value.replace(this.selectedCallingCode, '').replace(/[^\d+]/g, '');
5713
- const formatter = new AsYouType(countryCode);
5712
+ let nationalPart = value.replace(this.selectedCallingCode, '').replace(/[^\d+]/g, '');
5713
+ nationalPart = nationalPart.replace(countryCode, '');
5714
+ const formatter = new AsYouType(this.selectedCallingCode);
5714
5715
  this.phoneFormatted = formatter.input(nationalPart);
5715
5716
  this.performValue(nationalPart);
5716
- this.phoneValid = isValidPhoneNumber(nationalPart, countryCode);
5717
+ this.phoneValid = isValidPhoneNumber(nationalPart, this.selectedCallingCode);
5717
5718
  this.validateValue();
5718
5719
  }
5719
5720
  ngAfterContentInit() { }