How to use the ngrx-forms.validate 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 / greater-than-or-equal-to.spec.ts View on Github external
it('should properly infer value type when used with validate update function', () => {
    // this code is never meant to be executed, it should just pass the type checker
    if (1 !== 1) {
      const state: AbstractControlState = undefined!;
      const v = validate(state, greaterThanOrEqualTo(0));
      const v2: number = v.value;
      console.log(v2);
    }
  });
});
github MrWolfZ / ngrx-forms / validation / src / min-length.spec.ts View on Github external
it('should properly infer value type when used with validate update function', () => {
    // this code is never meant to be executed, it should just pass the type checker
    if (1 !== 1) {
      const state: AbstractControlState = undefined!;
      const v = validate(state, minLength(2));
      const v2: string = v.value;
      console.log(v2);
    }
  });
});
github MrWolfZ / ngrx-forms / validation / src / required.spec.ts View on Github external
it('should properly infer value type when used with validate update function', () => {
    // this code is never meant to be executed, it should just pass the type checker
    if (1 !== 1) {
      const state: AbstractControlState = undefined!;
      const v = validate(state, required);
      const v2: number = v.value;
      console.log(v2);
    }
  });
});
github MrWolfZ / ngrx-forms / validation / src / less-than.spec.ts View on Github external
it('should properly infer value type when used with validate update function', () => {
    // this code is never meant to be executed, it should just pass the type checker
    if (1 !== 1) {
      const state: AbstractControlState = undefined!;
      const v = validate(state, lessThan(2));
      const v2: number = v.value;
      console.log(v2);
    }
  });
});
github MrWolfZ / ngrx-forms / validation / src / greater-than.spec.ts View on Github external
it('should properly infer value type when used with validate update function', () => {
    // this code is never meant to be executed, it should just pass the type checker
    if (1 !== 1) {
      const state: AbstractControlState = undefined!;
      const v = validate(state, greaterThan(0));
      const v2: number = v.value;
      console.log(v2);
    }
  });
});
github MrWolfZ / ngrx-forms / validation / src / required-true.spec.ts View on Github external
it('should properly infer value type when used with validate update function', () => {
    // this code is never meant to be executed, it should just pass the type checker
    if (1 !== 1) {
      const state: AbstractControlState = undefined!;
      const v = validate(state, requiredTrue);
      const v2: boolean = v.value;
      console.log(v2);
    }
  });
});
github MrWolfZ / ngrx-forms / example-app / src / app / material-example / material.reducer.ts View on Github external
});

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)),
    });
  },
  agreeToTermsOfUse: validate(requiredTrue),
}));

const reducers = combineReducers({
  formState(s = INITIAL_STATE, a: Action) {
    return validationFormGroupReducer(s, a);
  },
  submittedValue(s: FormValue | undefined, a: SetSubmittedValueAction) {
    switch (a.type) {
      case SetSubmittedValueAction.TYPE:
        return a.submittedValue;

      default:
        return s;
    }
  },
});
github MrWolfZ / ngrx-forms / example-app / src / app / app.reducer.ts View on Github external
import { Action } from '@ngrx/store';
import { groupUpdateReducer, updateGroup, setValue, validate, enable, disable, cast, compose } from 'ngrx-forms';

import { AppState, initialState, ITEM_FORM_ID } from './app.state';
import { Actions, AddTodoItemAction } from './app.actions';
import { ItemFormValue, MetaFormValue, validateText, validatePriority, validateDuedate } from './item-form/item-form.state';

const itemFormReducer = groupUpdateReducer({
  text: validate(validateText),
  meta: updateGroup({
    priority: validate(validatePriority),
    duedate: validate(validateDuedate),
  }),
}, {
    meta: (meta, itemForm) => updateGroup({
      priority: priority => {
        if (itemForm.value.category === 'Private') {
          return setValue(0, disable(priority));
        }

        return priority.isEnabled ? priority : setValue(1, enable(priority));
      },
    })(cast(meta)),
  });
github MrWolfZ / ngrx-forms / example-app / src / app / async-validation / async-validation.reducer.ts View on Github external
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;
    }

    return s;
  },
});

export function reducer(s: State['asyncValidation'], a: Action) {
github MrWolfZ / ngrx-forms / example-app / src / app / app.reducer.ts View on Github external
import { Action } from '@ngrx/store';
import { groupUpdateReducer, updateGroup, setValue, validate, enable, disable, cast, compose } from 'ngrx-forms';

import { AppState, initialState, ITEM_FORM_ID } from './app.state';
import { Actions, AddTodoItemAction } from './app.actions';
import { ItemFormValue, MetaFormValue, validateText, validatePriority, validateDuedate } from './item-form/item-form.state';

const itemFormReducer = groupUpdateReducer({
  text: validate(validateText),
  meta: updateGroup({
    priority: validate(validatePriority),
    duedate: validate(validateDuedate),
  }),
}, {
    meta: (meta, itemForm) => updateGroup({
      priority: priority => {
        if (itemForm.value.category === 'Private') {
          return setValue(0, disable(priority));
        }

        return priority.isEnabled ? priority : setValue(1, enable(priority));
      },
    })(cast(meta)),
  });

export function appReducer(state = initialState, action: Actions): AppState {
  const itemForm = itemFormReducer(state.itemForm, action);
  if (itemForm !== state.itemForm) {