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

subsequent focus actions #39

Closed
Kaffiend opened this issue Jan 31, 2018 · 2 comments
Closed

subsequent focus actions #39

Kaffiend opened this issue Jan 31, 2018 · 2 comments
Labels

Comments

@Kaffiend
Copy link

I'm firing off the below effect to reset the form and set focus, it works for the first submit, but all subsequent the focus action dispatches but the control is not focused.

  @Effect({dispatch: false})
  addDistrictSuccess$ = this.actions$
  .ofType(districtActions.DistrictActionTypes.AddDistrictSuccess)
  .do(() => {
    this.actionSubject.next(new FocusAction(districtForm.initialFormState.controls.districtName.id));
    this.actionSubject.next(new SetValueAction(districtForm.initialFormState.id, districtForm.initialFormState.value));
    this.actionSubject.next(new ResetAction(districtForm.initialFormState.id));
  });
@MrWolfZ
Copy link
Owner

MrWolfZ commented Jan 31, 2018

Have you added [ngrxEnableFocusTracking]="true" to the control in HTML? Only if this is set will the form control directive properly track focus changes. Without this what will happen is exactly what you observe. You focus the element once, but in the state it never becomes unfocused. And therefore it will not focus the element the second time since it thinks it is still focused.

PS: The reason the focus tracking is opt-in is that otherwise there would be quite the spam of actions when controls become focused and unfocused all the time.

@Kaffiend
Copy link
Author

I agree with the opt in, if i'm understanding correctly. Majority of forms you only have one or two focus events you want to track usually on reset to go back to the beginning and such. That also fixed the issue, thank you.

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

No branches or pull requests

2 participants