Skip to content

Commit d6ce00c

Browse files
apuntovaninirkuykendall
authored andcommitted
feat(changelog): Changelog with conventional-commits (#26)
* Adding Changelog
1 parent f8dc5f5 commit d6ce00c

File tree

6 files changed

+467
-133
lines changed

6 files changed

+467
-133
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<a name="1.1.0"></a>
2+
# [1.1.0](https://github.com/formsy/formsy-react/compare/v1.0.2...v1.1.0) (2017-11-21)
3+
4+
5+
### Features
6+
7+
* **react16:** add support for react16 by loosening dev and peer dependencies ([16b9065](https://github.com/formsy/formsy-react/commit/16b9065))
8+
9+
10+
11+

lib/Wrapper.js

Lines changed: 84 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,90 @@ exports.default = function (Component) {
7676

7777
var _this = _possibleConstructorReturn(this, (WrappedComponent.__proto__ || Object.getPrototypeOf(WrappedComponent)).call(this, props));
7878

79+
_this.getErrorMessage = function () {
80+
var messages = _this.getErrorMessages();
81+
return messages.length ? messages[0] : null;
82+
};
83+
84+
_this.getErrorMessages = function () {
85+
if (!_this.isValid() || _this.showRequired()) {
86+
return _this.state.externalError || _this.state.validationError || [];
87+
}
88+
return [];
89+
};
90+
91+
_this.getValue = function () {
92+
return _this.state.value;
93+
};
94+
95+
_this.setValidations = function (validations, required) {
96+
// Add validations to the store itself as the props object can not be modified
97+
_this.validations = convertValidationsToObject(validations) || {};
98+
_this.requiredValidations = required === true ? { isDefaultRequiredValue: true } : convertValidationsToObject(required);
99+
};
100+
101+
_this.setValue = function (value) {
102+
var validate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
103+
104+
if (!validate) {
105+
_this.setState({
106+
value: value
107+
});
108+
} else {
109+
_this.setState({
110+
value: value,
111+
isPristine: false
112+
}, function () {
113+
_this.context.formsy.validate(_this);
114+
});
115+
}
116+
};
117+
118+
_this.hasValue = function () {
119+
return _this.state.value !== '';
120+
};
121+
122+
_this.isFormDisabled = function () {
123+
return _this.context.formsy.isFormDisabled();
124+
};
125+
126+
_this.isFormSubmitted = function () {
127+
return _this.state.formSubmitted;
128+
};
129+
130+
_this.isPristine = function () {
131+
return _this.state.isPristine;
132+
};
133+
134+
_this.isRequired = function () {
135+
return !!_this.props.required;
136+
};
137+
138+
_this.isValid = function () {
139+
return _this.state.isValid;
140+
};
141+
142+
_this.isValidValue = function (value) {
143+
return _this.context.formsy.isValidValue.call(null, _this, value);
144+
};
145+
146+
_this.resetValue = function () {
147+
_this.setState({
148+
value: _this.state.pristineValue,
149+
isPristine: true
150+
}, function () {
151+
_this.context.formsy.validate(_this);
152+
});
153+
};
154+
155+
_this.showError = function () {
156+
return !_this.showRequired() && !_this.isValid();
157+
};
158+
159+
_this.showRequired = function () {
160+
return _this.state.isRequired;
161+
};
162+
79163
_this.state = {
80164
value: props.value,
81165
isRequired: false,
@@ -86,22 +170,6 @@ exports.default = function (Component) {
86170
externalError: null,
87171
formSubmitted: false
88172
};
89-
90-
_this.getErrorMessage = _this.getErrorMessage.bind(_this);
91-
_this.getErrorMessages = _this.getErrorMessages.bind(_this);
92-
_this.getValue = _this.getValue.bind(_this);
93-
_this.hasValue = _this.hasValue.bind(_this);
94-
_this.isFormDisabled = _this.isFormDisabled.bind(_this);
95-
_this.isPristine = _this.isPristine.bind(_this);
96-
_this.isFormSubmitted = _this.isFormSubmitted.bind(_this);
97-
_this.isRequired = _this.isRequired.bind(_this);
98-
_this.isValidValue = _this.isValidValue.bind(_this);
99-
_this.isValid = _this.isValid.bind(_this);
100-
_this.resetValue = _this.resetValue.bind(_this);
101-
_this.setValidations = _this.setValidations.bind(_this);
102-
_this.setValue = _this.setValue.bind(_this);
103-
_this.showRequired = _this.showRequired.bind(_this);
104-
_this.showError = _this.showError.bind(_this);
105173
return _this;
106174
}
107175

@@ -153,111 +221,10 @@ exports.default = function (Component) {
153221
value: function componentWillUnmount() {
154222
this.context.formsy.detachFromForm(this);
155223
}
156-
}, {
157-
key: 'getErrorMessage',
158-
value: function getErrorMessage() {
159-
var messages = this.getErrorMessages();
160-
return messages.length ? messages[0] : null;
161-
}
162-
}, {
163-
key: 'getErrorMessages',
164-
value: function getErrorMessages() {
165-
return !this.isValid() || this.showRequired() ? this.state.externalError || this.state.validationError || [] : [];
166-
}
167-
}, {
168-
key: 'getValue',
169-
value: function getValue() {
170-
return this.state.value;
171-
}
172-
}, {
173-
key: 'setValidations',
174-
value: function setValidations(validations, required) {
175-
// Add validations to the store itself as the props object can not be modified
176-
this.validations = convertValidationsToObject(validations) || {};
177-
this.requiredValidations = required === true ? { isDefaultRequiredValue: true } : convertValidationsToObject(required);
178-
}
179224

180225
// By default, we validate after the value has been set.
181226
// A user can override this and pass a second parameter of `false` to skip validation.
182227

183-
}, {
184-
key: 'setValue',
185-
value: function setValue(value) {
186-
var _this3 = this;
187-
188-
var validate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
189-
190-
if (!validate) {
191-
this.setState({
192-
value: value
193-
});
194-
} else {
195-
this.setState({
196-
value: value,
197-
isPristine: false
198-
}, function () {
199-
_this3.context.formsy.validate(_this3);
200-
});
201-
}
202-
}
203-
}, {
204-
key: 'hasValue',
205-
value: function hasValue() {
206-
return this.state.value !== '';
207-
}
208-
}, {
209-
key: 'isFormDisabled',
210-
value: function isFormDisabled() {
211-
return this.context.formsy.isFormDisabled();
212-
}
213-
}, {
214-
key: 'isFormSubmitted',
215-
value: function isFormSubmitted() {
216-
return this.state.formSubmitted;
217-
}
218-
}, {
219-
key: 'isPristine',
220-
value: function isPristine() {
221-
return this.state.isPristine;
222-
}
223-
}, {
224-
key: 'isRequired',
225-
value: function isRequired() {
226-
return !!this.props.required;
227-
}
228-
}, {
229-
key: 'isValid',
230-
value: function isValid() {
231-
return this.state.isValid;
232-
}
233-
}, {
234-
key: 'isValidValue',
235-
value: function isValidValue(value) {
236-
return this.context.formsy.isValidValue.call(null, this, value);
237-
// return this.props.isValidValue.call(null, this, value);
238-
}
239-
}, {
240-
key: 'resetValue',
241-
value: function resetValue() {
242-
var _this4 = this;
243-
244-
this.setState({
245-
value: this.state.pristineValue,
246-
isPristine: true
247-
}, function () {
248-
_this4.context.formsy.validate(_this4);
249-
});
250-
}
251-
}, {
252-
key: 'showError',
253-
value: function showError() {
254-
return !this.showRequired() && !this.isValid();
255-
}
256-
}, {
257-
key: 'showRequired',
258-
value: function showRequired() {
259-
return this.state.isRequired;
260-
}
261228
}, {
262229
key: 'render',
263230
value: function render() {

lib/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ var addValidationRule = function addValidationRule(name, func) {
556556
var withFormsy = _Wrapper2.default;
557557

558558
var deprecatedWrapper = function deprecatedWrapper(Component) {
559+
// eslint-disable-next-line no-console
559560
console.warn('Wrapper has been renamed to withFormsy. Importing Wrapper from formsy-react is depreacted and will be removed in the future. Please rename your Wrapper imports to withFormsy.');
560561

561562
return withFormsy(Component);

lib/validationRules.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ var validations = {
2727
return isEmpty(value);
2828
},
2929
isEmail: function isEmail(values, value) {
30-
return validations.matchRegexp(values, value, /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i);
30+
// Regex from http://emailregex.com/
31+
return validations.matchRegexp(values, value, /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/i);
3132
},
3233
isUrl: function isUrl(values, value) {
3334
return validations.matchRegexp(values, value, /^(?:\w+:)?\/\/([^\s.]+\.\S{2}|localhost[:?\d]*)\S*$/i);

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
"react-component",
1111
"validation"
1212
],
13+
"standard-version": {
14+
"skip": {
15+
"tag": true
16+
}
17+
},
1318
"license": "MIT",
1419
"homepage": "https://github.com/formsy/formsy-react",
1520
"bugs": "https://github.com/formsy/formsy-react/issues",
@@ -27,6 +32,7 @@
2732
"examples": "webpack-dev-server --config examples/webpack.config.js --content-base examples",
2833
"lint": "eslint src/**/*.js",
2934
"prepublish": "rm -Rf ./lib && babel ./src/ -d ./lib/",
35+
"changelog": "standard-changelog",
3036
"test": "babel-node testrunner"
3137
},
3238
"dependencies": {
@@ -52,6 +58,8 @@
5258
"react-addons-test-utils": "^15.6.0",
5359
"react-dom": "^15.6.1 || ^16.0.0",
5460
"sinon": "^3.2.0",
61+
"standard-changelog": "^1.0.5",
62+
"standard-version": "^4.2.0",
5563
"webpack": "^3.5.4",
5664
"webpack-dev-server": "^2.7.1"
5765
},

0 commit comments

Comments
 (0)