ngx-sub-form icon indicating copy to clipboard operation
ngx-sub-form copied to clipboard

emitInitialValueOnInit is missing

Open SergejSintschilin opened this issue 2 years ago • 9 comments

Hi.

Thank you for the great library.

I'm updating to the new released version and I saw that the options emitInitialValueOnInit is missing. Can you please return back this feature.

I want the emit my re-mapped value right away.

SergejSintschilin avatar Nov 23 '21 14:11 SergejSintschilin

Woops looks like we've forgotten about that one :o

If anyone is keen to look into it please let me know.

maxime1992 avatar Jan 03 '22 17:01 maxime1992

@maxime1992 I use the manualSave$ Subject in order to trigger a save Action that calls the Rest Api, only after a save button is pressed. Right now if I edit a Model and make no changes I can click the save button, but nothing happens. I would like to enable manualSave even though nothing changed. I already set this property in the root form: outputFilterPredicate: (currentInputValue: ChartFormModel, outputValue: ChartFormModel) => true, Another option would be do disable the save button until a formValue is changed, but I do not know where to check this. Is the emitInitialValueOnInit option a solution for my problem? I can not find that property on the root form though.

ChrTall avatar May 06 '22 17:05 ChrTall

@ChrTall yes that was done on purpose. You can see the code here:

https://github.com/cloudnc/ngx-sub-form/blob/4ab93f6e83b993d90ce4f7c4fc8e56c9b5b3ce00/projects/ngx-sub-form/src/lib/deprecated/ngx-root-form.component.ts#L70-L72

The reason being, if nothing changes why would you save it again, maybe just discard the edit

maxime1992 avatar May 09 '22 07:05 maxime1992

Hello 👋 we are actually facing the same problem.

We need to be able to manually save the form even if the input data are equal to the form values and the form was not touched for API reasons.

We also tried to use outputFilterPredicate: (currentInputValue: ChartFormModel, outputValue: ChartFormModel) => true, which from it's doc definition should do the job, but nothing happens.

Any reason / fix for this ?

imadhy avatar Aug 30 '22 14:08 imadhy

@ChrTall yes that was done on purpose. You can see the code here:

https://github.com/cloudnc/ngx-sub-form/blob/4ab93f6e83b993d90ce4f7c4fc8e56c9b5b3ce00/projects/ngx-sub-form/src/lib/deprecated/ngx-root-form.component.ts#L70-L72

The reason being, if nothing changes why would you save it again, maybe just discard the edit

@maxime1992

We also run into the same issue and I understand that you would not want to save as the data has not been changed. However, is there a way to know nothing has changed in the form? So we could disable the save button or show a message to inform the user nothing has changed :)?

svenank3r avatar Oct 25 '22 11:10 svenank3r

There's not at the moment. I think that's a valid use case though and that there's no work around at the moment. So I'd be willing to accept a new class property exposing that state. Would you be willing to make a PR @svenank3r ?

In case you are, here's some guidance after taking a quick look: It will be looking a lot like this code.

It should be built in a way that the perf impact of comparing the input data with the current form value should only affect the forms that are using the new property. This shouldn't be a big deal as observables are lazy by nature (and the new property should be an observable).

maxime1992 avatar Oct 25 '22 14:10 maxime1992

@maxime1992 I will look into and see if I can come up with a fix

svenank3r avatar Oct 26 '22 11:10 svenank3r

@imadhy @ChrTall

Hello 👋 we are actually facing the same problem.

We need to be able to manually save the form even if the input data are equal to the form values and the form was not touched for API reasons.

We also tried to use outputFilterPredicate: (currentInputValue: ChartFormModel, outputValue: ChartFormModel) => true, which from it's doc definition should do the job, but nothing happens.

Any reason / fix for this ?

I don't know if this is still of any use to you, but I do understand why the outputFilterPredicate is not working as you expect. The filter only works after a change has been made to the form, so if the form is not touched it will not be used. You can however have a workaround for this issue by disabling the save button (or any form you have in HTML) by checking the dirty state: <button [disabled]="!form.formGroup.dirty" (click)="save()"></button>

The combination of the outputFilterPredicate and the dirty check can enable you still make changes after the form has been tocuhed. Always being able to save (even when the form has not been touched) is not possible.

svenank3r avatar Jan 05 '23 11:01 svenank3r

Hello 👋 we are actually facing the same problem.

We need to be able to manually save the form even if the input data are equal to the form values and the form was not touched for API reasons.

We also tried to use outputFilterPredicate: (currentInputValue: ChartFormModel, outputValue: ChartFormModel) => true, which from it's doc definition should do the job, but nothing happens.

Any reason / fix for this ?

I also would need the same: the ability to manually save even if the form value was not changed. On a side-note: is it possible to somehow trick ngx-sub-form into thinking that the initial value is empty? Some combination of form.formGroup.patchValue() and/or input$.next()? I didn't manage to accomplish that...

NgrNxk avatar Jan 11 '23 11:01 NgrNxk