gcanti / tcomb-form

Forms library for react
https://gcanti.github.io/tcomb-form
MIT License
1.16k stars 136 forks source link

Incosistent calling of tcomb-validation validate function in getTypeInfo and components for struct and list types #253

Closed minedeljkovic closed 8 years ago

minedeljkovic commented 8 years ago
  1. In Struct and List components, t.validate is called with value that is built by their child components (i.e. with values that are results of calling child components validate method).
  2. In getTypeInfo (util module), or more precise in getValidationErrorMessage method that is built, t.validate is called with value that is received from base Component's getError method. That value is built from state with calling top level transformer only.

One of the consequences is that if struct or list item type has properties of types that are parsed by their own transformers (e.g. number type), and valid strings are set for those properties, case 1. will not find validation errors (since those strings are parsed by their components, when their validate method is called), but case 2. will find validation errors (since those strings are not parsed)

gcanti commented 8 years ago

Hi @minedeljkovic ! thanks for pointing out.

Yes it's inconsistent, honestly I'm not that proud of that code, it's the fruit of too many tweaks.

Working on this...

p.s. it's difficult to find a test case that raises an inconsistent behaviour. Do you have a "failing" test case at hand?

minedeljkovic commented 8 years ago

It is not easy to write a proper test in current test suite, since it depends on setState and that requires components to be mounted. I hacked it heavily and tried to back it up with comments. You can find it here: https://github.com/minedeljkovic/tcomb-form/blob/master/test/components/Component.js#L165

I am not sure if this is helpful. :(

gcanti commented 8 years ago

Thanks a lot @minedeljkovic, just pushed a fix on master