last day (16 days later) » 

10:30 AM
1
A: Angular - Dynamic input form array fails to update

Yong ShunIn your FormGroup, there is no employeephones FormArray, but it is contacts FormArray. updateContact() { this.contactInfoForm = this.fb.group({ id: [''], current_residential_address: ['', [Validators.required]], contacts: this.fb.array([this.addContactFormGroup()]), }); } mapForm...

 
Note: There is some error(s) in the attached source code, hence the solution on Stackbliz above is to minimally reproduce and fix the error.
 
Thanks so much. Because of the package I used, How do I select phone_number.e164Number console.log(this.contactdata.employeephones) now gives 0: is_primary_contact_number: true phone_number: countryCode: "NG" dialCode: "+234" e164Number: "+2349099999999" internationalNumber: "+234 909 999 9999" nationalNumber: "0909 999 9999" number: "909 999 9999"
 
Hi, which phone number will you use? I will update my answer based on it, thanks
 
I am taking e164Number for the phone_number
 
Hi, done update my answer, since this.contactInfoForm.value.contacts.phone_number return Object, I believe it is returned from ngx-intl-tel-input, so you need map to get the desired output.
 
10:30 AM
It works. Thanks so mu @YongShun
@YongSun - I have a question. console.log(this.contactdata.employeephones) gives result, while console.log(mapFormValueForContactModel()) gives undefined. Why is it so?
 
Hi
```typescript
mapFormValueForContactModel() {
this.contactdata.current_residential_address =
this.contactInfoForm.value.current_residential_address;
this.contactInfoForm.value.contacts.map(
(value) => {
return {
phone_type_id: value.phone_type_id,
is_primary_contact_number: value.is_primary_contact_number,
phone_number: value.phone_number.e164Number
};
}
);
}
```
As this method without any return, thus when you console.log(mapFormValueForContactModel()) you will get no value
Unless you modify this method to return value.
 
Hello
This is what I used
mapFormValueForContactModel() {
this.contactdata.current_residential_address =
this.contactInfoForm.value.current_residential_address;
this.contactdata.employeephones = this.contactInfoForm.value.contacts.map(
(value: any) => {
return {
phone_type_id: value.phone_type_id,
is_primary_contact_number: value.is_primary_contact_number,
phone_number: value.phone_number.e164Number,
};
}
);
}
 
10:46 AM
Hmmm
 
The backend is not getting anything except current_residential_address
But have this in the console ErrorException: Trying to access array offset on value of type null
Why is it not getting the array?
 
So when you console.log(this.contactdata), what is the value? Before sending request to backend
Sorry I don't have experience in Laravel, but based on this question: https://stackoverflow.com/questions/59322150/trying-to-access-array-offset-on-value-of-type-null

It seems like your backend doesn't receive the value for employeephones array
 
Where do I console console.log(this.contactdata)
Do you mean the problem is from the backend?
 
The arrow line before you post data with employeeService
@user11352561 Just to confirm is it due to front end part before proceed to back end
 
current_residential_address: "testing2"
employeephones: Array(2)
0:
is_primary_contact_number: true
phone_number: "+2349099999999"
phone_type_id: 1
[[Prototype]]: Object
1:
is_primary_contact_number: ""
phone_number: "+2348088888888"
phone_type_id: 2
[[Prototype]]: Object
length: 2
 
10:58 AM
Ok
Does this request data match with your backend expected input type?
 
Yes, See the backend
if(!$employee) return $this->error('No Employee with ID '.$id, 404);
$employee->current_residential_address = $request->current_residential_address;
$employee->save();


foreach (Arr::wrap($request->phone_number) as $key => $phone_number){
$phone = new EmployeePhone();
$phone->phone_number = $request->phone_number[$key];
$phone->phone_type_id = $request->phone_type_id[$key];
$phone->is_primary_contact_number = $request->is_primary_contact_number[$key];
 
Hmmm
Maybe you try change $request->employeephones instead of $request->phone_number
Because the phone_number doesn't exist in your request
 
But this is in the console.log: phone_number: "+2349099999999"
 
Okay
What do I now set as $key => $phone_number
foreach (Arr::wrap($request->employeephones) as $key => $phone_number)
 
11:09 AM
as $key => $phone_number

this means index right? I predict the style based on your logic
Because I really don't know Laravel syntax hahaha
I believe if you debug $request->employeephones contains value, that means you get the input correctly
 
Yes, I will. You've really tried. Thanks
 
Oh ya, FYI, I update my answer as the image attached above, I recheck and found this.contactdata.employeephones = was removed accidentally. Sorry about that.
@user11352561 Ok thanks too. Fingers crossed.
 
No problems. Thanks
 

  last day (16 days later) »