Excluding empty form <input> from POST/PATCH requests

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.

You’ve created an internal civil war.

When using two-way [(ngModel)] bindings, let whatever that binding is do its thing and get out of its way. This means getting rid of value in the template and instead assigning in the controller doing things like:

inputData.field_a.value = getData.field_a.value;

Thanks for pointing that out.

I was doing a *ngFor=“let items of getData” where getData value is from result of a http.get(). I then did a {{items.value}} as display/label of current value. I thought i could use it too as the default value for input fields.

That said, what should be the included with input in exchange to removing value="{{}}"?. Would making assigning inputData = getData and leaving [(ngmodel)] as is for input and display suffice? Pardon my lack of understanding. Thanks again.