Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two way binding of phone number is one way only #9

Open
DavidTalamona opened this issue Feb 11, 2020 · 4 comments
Open

Two way binding of phone number is one way only #9

DavidTalamona opened this issue Feb 11, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@DavidTalamona
Copy link

Expected behavior

The end user should be able to change an existing phone number.
Two way binding of the intl-tel-input should accept input.

Actual behavior

When I pass an existing value into the component like this: [(E164PhoneNumber)]="data.mobile", the value is never set in the field.

Steps to reproduce

TS:
data = {mobile: '+41791234567'};
HTML:
<intl-tel-input name="mobile" [(E164PhoneNumber)]="data.mobile" required></intl-tel-input>

intl-tel-input-ng version

0.0.7 & 0.1.0

@mpalourdio
Copy link
Owner

Thanks for feedback, but actually this is 'by design', but I have to admit this is a bit weird. I had made this little lib in a quick way to integrate it in a project.

Givin the ability to set the value in the field is a bit tedious, because we need to target the intl-tel-input main API after the component initialization, which happens once the DOM is ready, in AfterViewInit.

Marking this as feature request, will see if I have time to make this feature later.

Thanks again!

@mpalourdio mpalourdio added the enhancement New feature or request label Feb 11, 2020
@danielehrhardt
Copy link

i mean you can do the following:

  @Input() public E164PhoneNumber: string;
  @Output() private E164PhoneNumberChange = new EventEmitter<string>();

....


  get phoneNumber(): string {
    return this.E164PhoneNumber;
  }

  set phoneNumber(value: string) {
    if (!!value) {
      this._intlTelInput.setNumber(value);
    }
    this.E164PhoneNumber = value;
    this.i18nizePhoneNumber();
  }

  public i18nizePhoneNumber(): void {
    this.E164PhoneNumber = null;
    if (this._intlTelInput.isValidNumber()) {
      this.E164PhoneNumber = this._intlTelInput.getNumber();
    }
    this.E164PhoneNumberChange.emit(this.E164PhoneNumber);
  }

with this the following should work fine
[(E164PhoneNumber)]="data.mobile"

@mpalourdio
Copy link
Owner

mpalourdio commented Apr 19, 2020

If you try this as is, you will see that this leads to problems. The difficulty is not to make the double binding of the phone value work, the problem is making things happen AFTER values binding in the intl-tel-input lib. (validation, country selection in the select list). We can rely on the component only in AfterViewInit, whereas in angular, @Input bindings happen on a different lifecycle hook before. So once the value is set by angular, the intl-tel-input component may not be ready yet.

The lib has a promise we can rely on but it makes things a bit tedious to implement. (but not that much I think)

But PR are of course welcome to implement this feature.

@HamzaAudeh
Copy link

Hello,

Any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants