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

Possible bug on manual save #291

Closed
188599 opened this issue Jan 6, 2023 · 3 comments
Closed

Possible bug on manual save #291

188599 opened this issue Jan 6, 2023 · 3 comments

Comments

@188599
Copy link

188599 commented Jan 6, 2023

I'm having some trouble figuring out why the form is not emitting it's value to the output$ subject after invoking manualSave$. It works as intended for anything but one specific form entry, when trying to edit it.

At the moment when manualSave$ emits, I make sure the form is valid. Also it does not seem to change states, which I checked by subscribing to formGroup.statusChanges.

This is the method I call for when attempting to submit the form.

    public async submit() {
        if (!this.form.formGroup.valid) {
            this.form.formGroup.markAllAsTouched();

            this.errorsWarning = true;

            this.sidenavContent.scrollTo({ top: 0, behavior: "smooth" });

            this.form.formGroup.statusChanges
                .pipe(
                    takeWhile(status => status !== 'VALID'),
                    take(1),
                    finalize(() => this.errorsWarning = false)
                )
                .subscribe();

            return;
        }

        if (this.form.formGroup.valid) {
            // manualSave$
            this.manualSave$$.next();

            // added this for debugging
            merge(
                this.form.controlValue$, // this one seems to emit
                this.form.formGroup.statusChanges.pipe(take(1)) // this one doest not
            )
                .pipe(tap(data => { debugger }))
                .subscribe();

            return;
        }

        await lastValueFrom(
            this.form.formGroup.statusChanges
                .pipe(
                    startWith(this.form.formGroup.status),
                    takeWhile(status => status === 'PENDING')
                )
        );

        await this.submit();
    }

I can't really find a way to properly debug the code from the library and even looking through the code I didn't find any other caveats that might be causing this issue for me.

I also tried cloning this repository and using it as a local dependency to enable proper debugging, but I'm running on some issues when trying to compile my project, due to some mismatch with angular versions that I'm not quite sure how to resolve.

Any ideas on how to proceed with this would be appreciated.

@188599
Copy link
Author

188599 commented Jan 6, 2023

I just found ngx-sub-form.mjs on Chrome's Devtools. I'm gonna see if I can figure out the issue. I don't know how I missed that before. 🤦‍♂️

Keeping the issue open for now, will close later or add more details once I figure out the problem.

@188599
Copy link
Author

188599 commented Jan 6, 2023

Figured out the problem.

I was just trying to submit a form without making any changes, but there's this equality check before emitting.

I guess it wouldn't make much sense to submit the form back without any value changes. I'm closing the issue.

@188599 188599 closed this as completed Jan 6, 2023
@maxime1992
Copy link
Contributor

Nice debugging @188599.

You may want to follow #290 and #289

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants