File tree Expand file tree Collapse file tree 4 files changed +64
-4
lines changed
Expand file tree Collapse file tree 4 files changed +64
-4
lines changed Original file line number Diff line number Diff line change 3737 - [ validate] ( #validate )
3838 - [ formNoValidate] ( #formnovalidate )
3939- [ Formsy.HOC] ( #formsyhoc )
40+ - [ innerRef] ( #innerRef )
4041- [ Formsy.Decorator] ( #formsydecorator )
4142- [ Formsy.addValidationRule] ( #formsyaddvalidationrule )
4243- [ Validators] ( #validators )
@@ -566,7 +567,7 @@ The same methods as the mixin are exposed to the HOC version of the element comp
566567``` jsx
567568import {HOC } from ' formsy-react' ;
568569
569- class MyInput extends React .Component {
570+ class MyInputHoc extends React .Component {
570571 render () {
571572 return (
572573 < div>
@@ -575,9 +576,30 @@ class MyInput extends React.Component {
575576 );
576577 }
577578};
578- export default HOC (MyInput );
579+ export default HOC (MyInputHoc );
579580```
580581
582+ #### <a name =" innerRef " >innerRef</a >
583+
584+ Use an ` innerRef ` prop to get a reference to your DOM node.
585+
586+ ``` jsx
587+ var MyForm = React .createClass ({
588+ componentDidMount () {
589+ this .searchInput .focus ()
590+ },
591+ render : function () {
592+ return (
593+ < Formsy .Form >
594+ < MyInputHoc name= " search" innerRef= {(c ) => { this .searchInput = c; }} / >
595+ < / Formsy .Form >
596+ );
597+ }
598+ })
599+ ```
600+
601+ Sets a class name on the form itself.
602+
581603### <a name =" formsydecorator " >Formsy.Decorator</a >
582604The same methods as the mixin are exposed to the decorator version of the element component, though through the ` props ` , not on the instance.
583605``` jsx
Original file line number Diff line number Diff line change @@ -4,8 +4,10 @@ module.exports = function (Component) {
44 return React . createClass ( {
55 displayName : 'Formsy(' + getDisplayName ( Component ) + ')' ,
66 mixins : [ Mixin ] ,
7+
78 render : function ( ) {
8- return React . createElement ( Component , {
9+ const { innerRef } = this . props ;
10+ const propsForElement = {
911 setValidations : this . setValidations ,
1012 setValue : this . setValue ,
1113 resetValue : this . resetValue ,
@@ -22,7 +24,12 @@ module.exports = function (Component) {
2224 showError : this . showError ,
2325 isValidValue : this . isValidValue ,
2426 ...this . props
25- } ) ;
27+ } ;
28+
29+ if ( innerRef ) {
30+ propsForElement . ref = innerRef ;
31+ }
32+ return React . createElement ( Component , propsForElement ) ;
2633 }
2734 } ) ;
2835} ;
Original file line number Diff line number Diff line change @@ -4,12 +4,30 @@ import TestUtils from 'react-addons-test-utils';
44
55import Formsy from './..' ;
66import TestInput from './utils/TestInput' ;
7+ import TestInputHoc from './utils/TestInputHoc' ;
78import immediate from './utils/immediate' ;
89import sinon from 'sinon' ;
910
1011export default {
1112
1213 'Setting up a form' : {
14+ 'should expose the users DOM node through an innerRef prop' : function ( test ) {
15+ const TestForm = React . createClass ( {
16+ render ( ) {
17+ return (
18+ < Formsy . Form >
19+ < TestInputHoc name = "name" innerRef = { ( c ) => { this . name = c ; } } />
20+ </ Formsy . Form >
21+ ) ;
22+ }
23+ } ) ;
24+
25+ const form = TestUtils . renderIntoDocument ( < TestForm /> ) ;
26+ const input = form . name ;
27+ test . equal ( input . methodOnWrappedInstance ( 'foo' ) , 'foo' ) ;
28+
29+ test . done ( ) ;
30+ } ,
1331
1432 'should render a form into the document' : function ( test ) {
1533
Original file line number Diff line number Diff line change 1+ import React from 'react' ;
2+ import { HOC as formsyHoc } from './../..' ;
3+
4+ const defaultProps = {
5+ methodOnWrappedInstance ( param ) {
6+ return param ;
7+ } ,
8+ render ( ) {
9+ return ( < input /> ) ;
10+ } ,
11+ } ;
12+
13+ export default formsyHoc ( React . createClass ( defaultProps ) ) ;
You can’t perform that action at this time.
0 commit comments