Skip to content

Commit

Permalink
Merge pull request #91 from andrewhathaway/reffix
Browse files Browse the repository at this point in the history
Fix Refs
  • Loading branch information
andrewhathaway committed Jul 13, 2017
2 parents 6384d1f + dd4e7d0 commit b229003
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 20 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,11 @@
# Change Log

# [1.1.4](https://github.com/andrewhathaway/Winterfell/releases/tag/1.1.4) (2017-07-13)

**Fixed bugs:**

- Switch to new React Ref handling from previous ways

# [1.1.3](https://github.com/andrewhathaway/Winterfell/releases/tag/1.1.3) (2017-05-01)

**Fixed bugs:**
Expand Down
12 changes: 10 additions & 2 deletions dist/index.js
Expand Up @@ -22,6 +22,8 @@ var Winterfell = (function (_React$Component) {

_get(Object.getPrototypeOf(Winterfell.prototype), 'constructor', this).call(this, props);

this.formComponent = null;

// Set our default values for props.
var props = _.extend({
schema: {
Expand Down Expand Up @@ -133,7 +135,11 @@ var Winterfell = (function (_React$Component) {
this.setState({
action: action
}, function () {
ReactDOM.findDOMNode(_this.refs[_this.props.ref]).submit();
if (!_this.formComponent) {
return;
}

_this.formComponent.submit();
});
}
}, {
Expand All @@ -150,7 +156,9 @@ var Winterfell = (function (_React$Component) {
{ method: this.props.method,
encType: this.props.encType,
action: this.state.action,
ref: this.props.ref,
ref: function (ref) {
return _this2.formComponent = ref;
},
className: this.state.schema.classes.form },
React.createElement(
'div',
Expand Down
29 changes: 17 additions & 12 deletions dist/winterfell.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "winterfell",
"version": "1.1.3",
"version": "1.1.4",
"description": "Generate complex, validated and extendable JSON-based forms in React",
"main": "dist/index.js",
"scripts": {
Expand Down Expand Up @@ -33,8 +33,8 @@
"babelify": "^6.3.0",
"keycodez": "^1.0.0",
"lodash": "^3.10.1",
"react": "^15.3.0",
"react-dom": "^15.3.0",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"validator": "^4.0.5"
},
"devDependencies": {
Expand Down
11 changes: 8 additions & 3 deletions src/index.js
Expand Up @@ -9,6 +9,8 @@ class Winterfell extends React.Component {
constructor(props) {
super(props);

this.formComponent = null;

// Set our default values for props.
var props = _.extend({
schema : {
Expand Down Expand Up @@ -123,8 +125,11 @@ class Winterfell extends React.Component {
this.setState({
action : action
}, () => {
ReactDOM.findDOMNode(this.refs[this.props.ref])
.submit();
if (!this.formComponent) {
return;
}

this.formComponent.submit();
});
}

Expand All @@ -136,7 +141,7 @@ class Winterfell extends React.Component {
<form method={this.props.method}
encType={this.props.encType}
action={this.state.action}
ref={this.props.ref}
ref={ref => this.formComponent = ref}
className={this.state.schema.classes.form}>
<div className={this.state.schema.classes.questionPanels}>
<QuestionPanel schema={this.state.schema}
Expand Down

0 comments on commit b229003

Please sign in to comment.