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

Error FromGroupState property undefined with validation required #64

Closed
r-khr opened this issue Apr 20, 2018 · 2 comments
Closed

Error FromGroupState property undefined with validation required #64

r-khr opened this issue Apr 20, 2018 · 2 comments

Comments

@r-khr
Copy link
Contributor

r-khr commented Apr 20, 2018

There are errors when creating a FromGroupState with undefined property as initial state and validation.

const FORM_ID = 'profile';

export interface IProfile {
  name: string;
  age: number;
}

export const INITIAL_STATE = createFormGroupState<IProfile>(FORM_ID, {
  name: undefined,
  age: undefined,
});

const validationFormGroupReducer = createFormGroupReducerWithUpdate<IProfile>({
  name: validate<string>(required),
});

export function profileReducer(_s: any, _a: any) {
  return combineReducers<any, any>({
    formState(s = INITIAL_STATE, a: Action) {
      return validationFormGroupReducer(s, a);
    },
  })(_s, _a);
}

Errors in browser bellow

TypeError: Cannot read property 'length' of undefined
    at required (validation.es5.js:434)
    at eval (forms.es5.js:2274)
    at Array.reduce (<anonymous>)
    at validate (forms.es5.js:2274)
    at Object.eval [as name] (forms.es5.js:2277)
    at eval (forms.es5.js:2076)
    at Array.reduce (<anonymous>)
    at eval (forms.es5.js:2072)
    at eval (forms.es5.js:2092)
    at eval (forms.es5.js:2114)

ProfileComponent.html:9 ERROR TypeError: Cannot read property 'profile' of undefined
    at MapSubscriber.exports.profileSelector [as project] (profile.selector.ts:4)
    at MapSubscriber._next (map.js:79)
    at MapSubscriber.Subscriber.next (Subscriber.js:95)
    at MapSubscriber._next (map.js:85)
    at MapSubscriber.Subscriber.next (Subscriber.js:95)
    at ReplaySubject._subscribe (ReplaySubject.js:61)
    at ReplaySubject.Observable._trySubscribe (Observable.js:172)
    at ReplaySubject.Subject._trySubscribe (Subject.js:98)
    at ReplaySubject.Observable.subscribe (Observable.js:160)
    at Observable._subscribe (Observable.js:231) 

ProfileComponent.html:9 ERROR TypeError: Cannot read property 'name' of null
    at Object.eval [as updateDirectives] (ProfileComponent.html:11)
    at Object.debugUpdateDirectives [as updateDirectives] (core.js:14655)
    at checkAndUpdateView (core.js:13802)
    at callViewAction (core.js:14153)
    at execComponentViewsAction (core.js:14085)
    at checkAndUpdateView (core.js:13808)
    at callViewAction (core.js:14153)
    at execEmbeddedViewsAction (core.js:14111)
    at checkAndUpdateView (core.js:13803)
    at callViewAction (core.js:14153)

No problem when value of name is set to null.

@MrWolfZ
Copy link
Owner

MrWolfZ commented Apr 20, 2018 via email

@MrWolfZ
Copy link
Owner

MrWolfZ commented Jul 22, 2018

I have just released version 3.0.0 which supports null and undefined form control values.

@MrWolfZ MrWolfZ closed this as completed Jul 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants