tanansatpal / ngx-mat-intl-tel-input

MIT License
62 stars 112 forks source link

How to pre-populate input field and stop too many numbers or editing from emptying the input field #34

Open sandra023 opened 4 years ago

sandra023 commented 4 years ago

I'm using this as part of an information form that can be filled out, then saved, then edited. So i need a way to have a saved number populate the input field not the placeholder. Because if they save the form with an imputed phone number the next time they save the form if they dont fill in a new number the field will be blank and it will overwrite the phone number that was stored with a null.

Also, When you enter in a phone number, if you go 1 number over the validated amount it erases the entire number. Which is very frustrating to have to retype it if I accidentally type one number to many. It already shows red if its an invalid number, so I don't need it to erase the entire thing. If I leave the field then go back to edit the number I imputed it erases the entire number. Id like to get ride of that too.

Also, I want to save the number in the formatted version it shows me after I type in the whole number. But the save function just gives me the number in its raw formatted version. Is there a way to access/save the number in its formatted version?

Mahmoud-64 commented 3 years ago

if you are using angular reactive forms you can just do the following to prepopulate tel field while editing

ngOnInit() { this.editForm = new FormGroup({ phone: new FormControl(this.user.phone, [Validators.required]), }); }

the first parameter of FormControl constructor is the initial value