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

FormArrayState, the state doesn't update when SetValueActions are disptached #308

Open
achraf-elk opened this issue May 25, 2023 · 0 comments
Labels

Comments

@achraf-elk
Copy link

As l input values to my form I can see the SetValueActions dispatched with the redux dev tools, the action contains the correct value and array index id. but the state doesn't get updated

My setup

Reducer:

export const creationCommandeFeatureKey: string = 'creationCommande';

export interface CommandCreationForm {
  numeroCommande: number | undefined;
  Boxed<FormArrayState<CommandPoste>;
}

export interface CommandCreationFormState {
  commandCreationForm: FormGroupState<CommandCreationForm>;
}

export const initialCommandPostsArrayForm: FormArrayState<CommandPoste> =
  createFormArrayState<CommandPoste>('commandPostsArrayForm', [
    {
      montant: undefined,
    },
  ]);

export const initialCommandCreationForm: FormGroupState<CommandCreationForm> =
  createFormGroupState<CommandCreationForm>('initialCommandCreationForm', {
    numeroCommande: undefined,
    posts: initialCommandPostsArrayForm,
  });

export const initialState: CommandCreationFormState = {
  commandCreationForm: initialCommandCreationForm,
};

export const commandCreationReducer: ActionReducer<CommandCreationFormState> = createReducer(
  initialState,
  onNgrxForms(),
))

Template:

<form [ngrxFormState]="createCommandeForm">
// rest of the form ...
<div>
       <div
         *ngFor="
           let arrayForm of createCommandeForm.controls.posts.value.value.controls;
           let first = first;
           let i = index
         "
       >
           <div>
             <span class="input-label">input*</span>
             <sds-input
               class="input"
               type="date"
               size="s"
               ngDefaultControl
               [ngrxFormControlState]="getFormControl(arrayForm).dateDebut"
             ></sds-input>
           </div>
</form>

Component:

in my component I am using the following method to properly cast the controls returned from the formArray

  getFormControl(control: FormState<CommandPoste>): FormGroupControls<CommandPoste> {
    return (control as unknown as FormGroupState<CommandPoste>).controls;
  }

Expected behavior
the state should be updated when the setValueAction is dispached

Screenshots
as i input a value in the form, the actions are correclty dispatched
image
but the state is still empty:
image

Library version:
8.0.0

@achraf-elk achraf-elk added the bug label May 25, 2023
@achraf-elk achraf-elk changed the title When using FormArrayState, the state doesn't update when SetValueAction is disptached FormArrayState, the state doesn't update when SetValueActions are disptached May 25, 2023
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

1 participant