gcanti / tcomb-form

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

use keys returned from getTypeProps as refs #269

Closed velveteer closed 8 years ago

velveteer commented 8 years ago

This might be heresy, but in one case I have nested refs inside of custom templates. When validating structs it iterates over all refs and will fail to call validate on my own refs (which are not tcomb generated components). I am open to other ways of achieving this.

gcanti commented 8 years ago

Hi,

Thanks for your PR.

getInputs() uses the keys of the object returned by getTypeProps() as refs, what about?

const props = this.getTypeProps() // <= same implementation of getInputs()
for (const ref in props) {
  if (this.refs.hasOwnProperty(ref)) {
    ....
  }
}

Note. Both validate() and getValue() should be changed accordingly.

velveteer commented 8 years ago

Ah I didn't see getTypeProps() but I figured it must exist somewhere. Thanks for pointing that out.

velveteer commented 8 years ago

@gcanti I think this PR makes sense considering we should only be iterating over known props instead of all possible refs inside of a struct component. Does this look good to you?

gcanti commented 8 years ago

Ah, yes. Sorry, I didn't notice your last commit yesterday, going to merge

gcanti commented 8 years ago

Released in https://github.com/gcanti/tcomb-form/releases/tag/v0.7.9, thanks @velveteer