How to use the ngrx-forms.box 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 / validation / src / min-length.spec.ts View on Github external
it('should not return an error if boxed string value\'s length is equal to minLength', () => {
    expect(minLength(2)(box('ab'))).toEqual({});
  });
github MrWolfZ / ngrx-forms / validation / src / greater-than.spec.ts View on Github external
it('should return errors with comparand and actual properties for boxed value', () => {
    const comparand = 1;
    const actual = box(0);
    expect(greaterThan(comparand)(actual)).toEqual({
      greaterThan: {
        comparand,
        actual: unbox(actual),
      },
    });
  });
github MrWolfZ / ngrx-forms / validation / src / less-than.spec.ts View on Github external
it('should not return an error if boxed value is less than comparand', () => {
    expect(lessThan(1)(box(0))).toEqual({});
  });
github MrWolfZ / ngrx-forms / validation / src / required-true.spec.ts View on Github external
it('should return an error for boxed false', () => {
    const value = box(false);
    expect(requiredTrue(value)).toEqual({
      required: {
        actual: unbox(value),
      },
    });
  });
github MrWolfZ / ngrx-forms / validation / src / not-equal-to.spec.ts View on Github external
it('should return errors with comparand and actual properties for boxed value', () => {
    const comparand = 1;
    const actualValue = box(1);
    expect(notEqualTo(comparand)(actualValue)).toEqual({
      notEqualTo: {
        comparand,
        actual: unbox(actualValue),
      },
    });
  });
github MrWolfZ / ngrx-forms / validation / src / required.spec.ts View on Github external
it('should return an error for boxed undefined', () => {
    const value = box(undefined);
    expect(required(value)).toEqual({
      required: {
        actual: unbox(value),
      },
    });
  });
github MrWolfZ / ngrx-forms / validation / src / max-length.spec.ts View on Github external
it('should not return an error if boxed string value\'s length is equal to maxLength', () => {
    expect(maxLength(2)(box('ab'))).toEqual({});
  });
github MrWolfZ / ngrx-forms / validation / src / required.spec.ts View on Github external
it('should work for boxed strings', () => {
    expect(required(box('a'))).toEqual({});
  });
github MrWolfZ / ngrx-forms / validation / src / required.spec.ts View on Github external
it('should return an error for boxed empty array', () => {
    const value = box([] as any[]);
    expect(required(value)).toEqual({
      required: {
        actual: unbox(value),
      },
    });
  });
github MrWolfZ / ngrx-forms / example-app / src / app / material-example / material.reducer.ts View on Github external
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) => {
    if (!parentState.value.createAccount) {
      return disable(state);
    }

    state = enable(state);
    return updateGroup(state, {
      password: validate(required, minLength(8)),
      confirmPassword: validate(equalTo(state.value.password)),
    });