Hi!
I’ve been trying to do a work-around for editing user profiles through REST API PATCH requests and I’ve stumbled upon a issue.
I’ve been trying to set-up a way on sending PATCH requests where empty input fields are not included OR re-use the current value of any field taken from GET request on PATCH request. This is for the purpose of retaining current field values if the user only wants to update specific ones and not all of them.
This is what I’ve been doing so far. getData.field_x.value is logged and has readable string output but it doesn’t work when using with {{}} for input default value
Case:
<ion-input [(ngModel)]=“inputData.field_a.value” value={{getData.field_a.value}}>
<ion-input [(ngModel)]=“inputData.field_b.value” value={{getData.field_b.value}}>
<ion-input [(ngModel)]=“inputData.field_c.value” value={{getData.field_b.value}}>
<ion-input [(ngModel)]=“inputData.field_d.value” value={{getData.field_b.value}}>
getData: string;
inputData = {
“field_a”: {“value”:"" },
“field_b”: {“value”:"" },
“field_c”: {“value”:"" },
“field_d”: {“value”:"" }
};
Since my initial solution doesn’t seem to work, I’d like to get suggestions on other ways to handle this.
What I’ve been thinking about are the ff:
1.) Exclude field_x on patch request if its input empty. Ex: if(inputData.field_a.value == null || inputData.field_a.value == ‘’) { this.http.patch(apiurl, inputData excluding field_a, headers)
2.) Find a way to make my initial idea work. ( is value="{{getData.field_a.value}}" the wrong way? )
I’ve also made forms with formbuilder but i find it more confusing. I’m willing to go that route if that’s the appropriate/better way.
Suggestions are very much appreciated.