React Bootstrap Validation use validated input in sub component

Will picture Will · Aug 26, 2015 · Viewed 8.7k times · Source

I am using react-bootstrap-validation that decorates the react-bootstrap Input tag.

The ValidatedInput requires that it is inside a Form component. When I add my ValidatedInput to a custom sub component I get an error saying it needs to be inside a Form which it is, but I guess it is further down the tree now so can not see the Form.

Is there a way of referencing the parent Form so the ValidatedInput can see the parent.

Looking at the source of the Validation lib I can see that the ValidationInput needs to register to the Form but am not sure how to do this from the sub component.

Answer

Ivan Reshetnikov picture Ivan Reshetnikov · Sep 3, 2015

At the moment this is impossible to do. It will be possible in a future release once we get proper parent-based contexts in react and I will migrate the component to contexts. But for now I would recommend to split your render() method to couple of smaller ones and reuse them.