How to use the ngrx-forms.createFormGroupState function in ngrx-forms

To help you get started, we’ve selected a few ngrx-forms examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MrWolfZ / ngrx-forms / example-app / src / app / local-state-advanced / local-state-advanced.reducer.ts View on Github external
constructor(public manufacturers: string[]) { }
}

export interface FormValue {
  countryCode: string;
  manufacturer: string;
}

export interface LocalState {
  manufacturers: string[];
  formState: FormGroupState;
}

export const FORM_ID = 'localStateForm';

export const INITIAL_FORM_STATE = createFormGroupState(FORM_ID, {
  countryCode: '',
  manufacturer: '',
});

export const INITIAL_LOCAL_STATE: LocalState = {
  manufacturers: [],
  formState: INITIAL_FORM_STATE,
};

const reducers = combineReducers({
  manufacturers(manufacturers = [], a: Action) {
    // update from loaded data
    if (a.type === SetManufacturersAction.TYPE) {
      return (a as SetManufacturersAction).manufacturers;
    }
    return manufacturers;
github MrWolfZ / ngrx-forms / example-app / src / app / sync-validation / sync-validation.reducer.ts View on Github external
export interface State extends RootState {
  syncValidation: {
    formState: FormGroupState;
    submittedValue: FormValue | undefined;
  };
}

export class SetSubmittedValueAction implements Action {
  static readonly TYPE = 'syncValidation/SET_SUBMITTED_VALUE';
  readonly type = SetSubmittedValueAction.TYPE;
  constructor(public submittedValue: FormValue) { }
}

export const FORM_ID = 'syncValidation';

export const INITIAL_STATE = createFormGroupState(FORM_ID, {
  userName: '',
  createAccount: true,
  password: {
    password: '',
    confirmPassword: '',
  },
  dayOfBirth: 1,
  monthOfBirth: 'January',
  yearOfBirth: 1970,
  agreeToTermsOfUse: false,
});

// @ts-ignore
declare module 'ngrx-forms/src/state' {
  interface ValidationErrors {
    passwordMatch?: PasswordValue;
github MrWolfZ / ngrx-forms / example-app / src / app / local-state-introduction / local-state-introduction.reducer.ts View on Github external
import { Action } from '@ngrx/store';
import { createFormGroupState, formGroupReducer, FormGroupState } from 'ngrx-forms';

export interface FormValue {
  countryCode: string;
}

export const FORM_ID = 'localStateForm';

export const INITIAL_FORM_STATE = createFormGroupState(FORM_ID, {
  countryCode: '',
});

export function reducer(fs: FormGroupState = INITIAL_FORM_STATE, a: Action) {
  return formGroupReducer(fs, a);
}
github MrWolfZ / ngrx-forms / example-app / src / app / async-validation / async-validation.reducer.ts View on Github external
export interface State extends RootState {
  asyncValidation: {
    formState: FormGroupState;
    searchResults: string[];
  };
}

export class SetSearchResultAction implements Action {
  static readonly TYPE = 'asyncValidation/SET_SEARCH_RESULT';
  readonly type = SetSearchResultAction.TYPE;
  constructor(public results: string[]) { }
}

export const FORM_ID = 'asyncValidation';

export const INITIAL_STATE = createFormGroupState(FORM_ID, {
  searchTerm: '',
  numberOfResultsToShow: 5,
});

const formGroupReducerWithUpdate = createFormStateReducerWithUpdate(updateGroup({
  searchTerm: validate(required),
  numberOfResultsToShow: validate(required, greaterThan(0)),
}));

const reducers = combineReducers({
  formState(s = INITIAL_STATE, a: Action) {
    return formGroupReducerWithUpdate(s, a);
  },
  searchResults(s: string[] = [], a: Action) {
    if (a.type === SetSearchResultAction.TYPE) {
      return (a as SetSearchResultAction).results;
github MrWolfZ / ngrx-forms / example-app / src / app / dynamic / dynamic.reducer.ts View on Github external
export class CreateGroupElementAction implements Action {
  static readonly TYPE = 'dynamic/CREATE_GROUP_ELEMENT';
  readonly type = CreateGroupElementAction.TYPE;
  constructor(public name: string) { }
}

export class RemoveGroupElementAction implements Action {
  static readonly TYPE = 'dynamic/REMOVE_GROUP_ELEMENT';
  readonly type = RemoveGroupElementAction.TYPE;
  constructor(public name: string) { }
}

export const FORM_ID = 'dynamic';

export const INITIAL_STATE = createFormGroupState(FORM_ID, {
  array: [false, false],
  group: {
    abc: false,
    xyz: false,
  },
});

export function formStateReducer(
  s = INITIAL_STATE,
  a: CreateGroupElementAction | RemoveGroupElementAction,
) {
  s = formGroupReducer(s, a);

  switch (a.type) {
    case CreateGroupElementAction.TYPE:
      return updateGroup({
github MrWolfZ / ngrx-forms / example-app / src / app / value-boxing / value-boxing.reducer.ts View on Github external
import { State as RootState } from '../app.reducer';

export interface FormValue {
  selection: Boxed;
}

export interface State extends RootState {
  valueBoxing: {
    formState: FormGroupState;
  };
}

export const FORM_ID = 'valueBoxing';

export const INITIAL_STATE = createFormGroupState(FORM_ID, {
  selection: box([2, 4]),
});

const reducers = combineReducers({
  formState(s = INITIAL_STATE, a: Action) {
    return formGroupReducer(s, a);
  },
});

export function reducer(s: State['valueBoxing'], a: Action) {
  return reducers(s, a);
}
github MrWolfZ / ngrx-forms / example-app / src / app / simple-form / simple-form.reducer.ts View on Github external
export interface State extends RootState {
  simpleForm: {
    formState: FormGroupState;
    submittedValue: FormValue | undefined;
  };
}

export class SetSubmittedValueAction implements Action {
  static readonly TYPE = 'simpleForm/SET_SUBMITTED_VALUE';
  readonly type = SetSubmittedValueAction.TYPE;
  constructor(public submittedValue: FormValue) { }
}

export const FORM_ID = 'simpleForm';

export const INITIAL_STATE = createFormGroupState(FORM_ID, {
  firstName: '',
  lastName: '',
  email: '',
  sex: '',
  favoriteColor: '',
  employed: false,
  notes: '',
});

const reducers = combineReducers({
  formState(s = INITIAL_STATE, a: Action) {
    return formGroupReducer(s, a);
  },
  submittedValue(s: FormValue | undefined, a: SetSubmittedValueAction) {
    switch (a.type) {
      case SetSubmittedValueAction.TYPE:
github MrWolfZ / ngrx-forms / example-app / src / app / array / array.reducer.ts View on Github external
import { State as RootState } from '../app.reducer';

export interface FormValue {
  options: boolean[];
}

export interface State extends RootState {
  array: {
    formState: FormGroupState;
  };
}

export const FORM_ID = 'array';

export const INITIAL_STATE = createFormGroupState(FORM_ID, {
  options: [
    false,
    false,
    false,
    false,
  ],
});

const reducers = combineReducers({
  formState(s = INITIAL_STATE, a: Action) {
    return formGroupReducer(s, a);
  },
});

export function reducer(s: State['array'], a: Action) {
  return reducers(s, a);
github MrWolfZ / ngrx-forms / example-app / src / app / material-example / material.reducer.ts View on Github external
export interface State extends RootState {
  material: {
    formState: FormGroupState;
    submittedValue: FormValue | undefined;
  };
}

export class SetSubmittedValueAction implements Action {
  static readonly TYPE = 'material/SET_SUBMITTED_VALUE';
  readonly type = SetSubmittedValueAction.TYPE;
  constructor(public submittedValue: FormValue) { }
}

export const FORM_ID = 'material';

export const INITIAL_STATE = createFormGroupState(FORM_ID, {
  userName: '',
  createAccount: true,
  password: {
    password: '',
    confirmPassword: '',
  },
  sex: '',
  favoriteColor: '',
  hobbies: box([]),
  dateOfBirth: new Date(Date.UTC(1970, 0, 1)).toISOString(),
  agreeToTermsOfUse: false,
});

const validationFormGroupReducer = createFormStateReducerWithUpdate(updateGroup({
  userName: validate(required),
  password: (state, parentState) => {
github MrWolfZ / ngrx-forms / example-app / src / app / app.state.ts View on Github external
readonly meta: {
    readonly priority: number;
    readonly duedate: string;
  };
}

export interface AppState {
  items: TodoItem[];
  itemForm: FormGroupState;
}

export const ITEM_FORM_ID = 'app/ITEM_FORM';

export const initialState: AppState = {
  items: [],
  itemForm: createFormGroupState(ITEM_FORM_ID, initialItemFormValue),
};

export interface RootState {
  app: AppState;
}