eManPrague / frui.ts

Pragmatic MVVM frontend framework
MIT License
14 stars 5 forks source link

Error with repeated validation inside ManualEntityValidator #11

Closed kopecmi8 closed 3 years ago

kopecmi8 commented 4 years ago

Hi, inside ManualEntityValidator at computed isValid method is an error. https://github.com/eManPrague/frui.ts/blob/develop/packages/validation/src/manualEntityValidator.ts#L30

Current implementantion doesnt react to changes inside errors object. Once the validation has occur by validate function than it doents react on object changes.

The scenario is:

  1. Validate invalid data
  2. Change data which is validated by server validator function and remove error by removeError method. Now is isValid set to true
  3. Revalidate form by sending request to server and addError. Now problem occur. isValid is not recomputed and validate method still returns true...

I think better implementation would be, which solves my problem:

import { keys } from "mobx";

@computed get isValid() {
    return keys(this.errors).length === 0;
  }
kopecmi8 commented 3 years ago

All seems fine now. Thank you