Skip to content

Commit

Permalink
Merge remote-tracking branch 'christ/master'
Browse files Browse the repository at this point in the history
* christ/master:
  0.18.1
  Fixed christianalfoni#335: getErrorMessages is undocumented in API
  Fixed christianalfoni#298: RangeError: Maximum call stack size exceeded with custom validator
  Fixed uncontrollable/controllable components in examples
  Fixed christianalfoni#361: Unknown props `onValidSubmit`, `onSubmitted` on <form> tag
  Use better names for components wrapped into HOC
  • Loading branch information
sdemjanenko committed Jul 11, 2016
2 parents d5240f0 + 6b167cb commit 8c1bc46
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 6 deletions.
4 changes: 4 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- [setValue()](#setvalue)
- [resetValue()](#resetvalue)
- [getErrorMessage()](#geterrormessage)
- [getErrorMessages()](#geterrormessages)
- [isValid()](#isvalid)
- [isValidValue()](#isvalidvalue)
- [isRequired()](#isrequired)
Expand Down Expand Up @@ -356,6 +357,9 @@ var MyInput = React.createClass({
```
Will return the validation message set if the form input component is invalid. If form input component is valid it returns **null**.

#### <a name="geterrormessages">getErrorMessages()</a>
Will return the validation messages set if the form input component is invalid. If form input component is valid it returns empty array.

#### <a name="isvalid">isValid()</a>
```jsx
var MyInput = React.createClass({
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-validation/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const DynamicInput = React.createClass({
return (
<div className={className}>
<label htmlFor={this.props.name}>{this.props.title}</label>
<input type='text' name={this.props.name} onChange={this.changeValue} value={this.getValue()}/>
<input type='text' name={this.props.name} onChange={this.changeValue} value={this.getValue() || ''}/>
<span className='validation-error'>{errorMessage}</span>
<Validations validationType={this.state.validationType} changeValidation={this.changeValidation}/>
</div>
Expand Down
1 change: 1 addition & 0 deletions examples/dynamic-form-fields/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const Fields = props => {
field.type === 'input' ?
(
<MyInput
value=""
name={`fields[${i}]`}
title={field.validations ? JSON.stringify(field.validations) : 'No validations'}
required={field.required}
Expand Down
4 changes: 2 additions & 2 deletions examples/login/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const App = React.createClass({
render() {
return (
<Form onSubmit={this.submit} onValid={this.enableButton} onInvalid={this.disableButton} className="login">
<MyInput name="email" title="Email" validations="isEmail" validationError="This is not a valid email" required />
<MyInput name="password" title="Password" type="password" required />
<MyInput value="" name="email" title="Email" validations="isEmail" validationError="This is not a valid email" required />
<MyInput value="" name="password" title="Password" type="password" required />
<button type="submit" disabled={!this.state.canSubmit}>Submit</button>
</Form>
);
Expand Down
2 changes: 1 addition & 1 deletion release/formsy-react.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion release/formsy-react.js.map

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions src/HOC.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var React = global.React || require('react');
var Mixin = require('./Mixin.js');
module.exports = function (Component) {
return React.createClass({
displayName: 'Formsy(' + getDisplayName(Component) + ')',
mixins: [Mixin],
render: function () {
return React.createElement(Component, {
Expand All @@ -25,3 +26,11 @@ module.exports = function (Component) {
}
});
};

function getDisplayName(Component) {
return (
Component.displayName ||
Component.name ||
(typeof Component === 'string' ? Component : 'Component')
);
}
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ Formsy.Form = React.createClass({
onSubmit: function () {},
onValidSubmit: function () {},
onInvalidSubmit: function () {},
onSubmitted: function () {},
onValid: function () {},
onInvalid: function () {},
onChange: function () {},
Expand Down Expand Up @@ -429,6 +428,7 @@ Formsy.Form = React.createClass({
validationErrors,
onSubmit,
onValid,
onValidSubmit,
onInvalid,
onInvalidSubmit,
onChange,
Expand Down
2 changes: 2 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ module.exports = {
return false;
} else if (Array.isArray(a)) {
return !this.arraysDiffer(a, b);
} else if (typeof a === 'function') {
return a.toString() === b.toString();
} else if (typeof a === 'object' && a !== null && b !== null) {
return !this.objectsDiffer(a, b);
}
Expand Down
4 changes: 4 additions & 0 deletions tests/Utils-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export default {
test.equal(utils.isSame(objA, objH), false);
test.equal(utils.isSame(objG, objA), false);

test.equal(utils.isSame(() => {}, () => {}), true);
test.equal(utils.isSame(objA, () => {}), false);
test.equal(utils.isSame(() => {}, objA), false);

test.done();

}
Expand Down

0 comments on commit 8c1bc46

Please sign in to comment.