Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emitInitialValueOnInit is missing #232

Open
SergejSintschilin opened this issue Nov 23, 2021 · 9 comments
Open

emitInitialValueOnInit is missing #232

SergejSintschilin opened this issue Nov 23, 2021 · 9 comments
Labels
type: bug/fix This is a bug or at least needs a fix

Comments

@SergejSintschilin
Copy link

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.

@maxime1992 maxime1992 added the type: bug/fix This is a bug or at least needs a fix label Jan 3, 2022
@maxime1992
Copy link
Contributor

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

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

@ChrTall
Copy link

ChrTall commented May 6, 2022

@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.

@maxime1992
Copy link
Contributor

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

if (this.formGroup.invalid || isEqual(data, this.dataInput$.value)) {
return false;
}

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

@imadhy
Copy link

imadhy commented Aug 30, 2022

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 ?

@svenank3r
Copy link

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

if (this.formGroup.invalid || isEqual(data, this.dataInput$.value)) {
return false;
}

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 :)?

@maxime1992
Copy link
Contributor

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).

@svenank3r
Copy link

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

@svenank3r
Copy link

svenank3r commented Jan 5, 2023

@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.

@NgrNxk
Copy link

NgrNxk commented Jan 11, 2023

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug/fix This is a bug or at least needs a fix
Projects
None yet
Development

No branches or pull requests

6 participants