question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hook to be warned when the form has changed?

See original GitHub issue

I think that a very common thing with form is subscribing to the form value and also start that observable with the current form value.

Example of doing that with this lib:

this.formGroup.valueChanges
      .pipe(
        startWith(this.formGroupValues),
        tap(() => this.doSomething())
      );

Annoying part is that in doing so, we have to manage the subscription and the cleanup when the component’s being destroyed.

I wonder if it would be worth having a method taking care of the whole observable/async part so that to react to a form change we would only need to do something like that:

@MyComponent({...})
class MyComponent extends NgxSubForm<FormInterface> {
  protected getFormControls(): Controls<FormInterface> {
    return {...};
  }

  protected onFormUpdate({ formValue, isInitialValue }: FormChange<FormInterface>) {
    // do something with formValue, also possible to make a condition if you don't want
    // to react to the initial value
  }
}

@zakhenry what do you think?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
zakhenrycommented, May 15, 2019

Oh oops I only saw the first example, yea I guess is initial is sufficient

On Wed, 15 May 2019 at 8:57 am, Maxime notifications@github.com wrote:

We should pass the index number so the inheriting class can ignore the first call if they want

Within my example I’ve got protected onFormUpdate({ formValue, isInitialValue }: FormChange<FormInterface>) do we really need to know the index? My initial thought was that isInitialValue (boolean) would be enough

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/cloudnc/ngx-sub-form/issues/34?email_source=notifications&email_token=AAFQE2N52UMCCKUPIUJMEOTPVO667A5CNFSM4HNAQUR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODVN3EXY#issuecomment-492548703, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFQE2ODGSO5LPVLUHCFGMTPVO667ANCNFSM4HNAQURQ .

– Zak Henry

0reactions
maxime1992commented, May 17, 2019

🎉 This issue has been resolved in version 2.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

React hook Form know when value is modified - Stack Overflow
Anyone have idea. I want know if any of the value is changed and update the state edited to true. After i provide...
Read more >
UserEvent.type causes act warning with react-hook-form with ...
When using fireEvent.change, the warning does not show up. I can wrap the userEvent.type in an act(), but I feel like that hides...
Read more >
useForm | React Hook Form - Simple React forms validation
useForm is a custom hook for managing forms with ease. ... By default, re-validation is actioned during the input change event.
Read more >
Rules of Hooks - React
Hooks are a new addition in React 16.8. They let you use state and other React features without writing a class. Hooks are...
Read more >
Integrated Public Alert & Warning System | FEMA.gov
The Integrated Public Alert & Warning System (IPAWS) is FEMA's national system for local alerting that provides authenticated emergency and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found