Skip to content
This repository was archived by the owner on Apr 30, 2018. It is now read-only.

Commit 1603f62

Browse files
committed
v7.0.0
2 parents b245620 + 9e4ba87 commit 1603f62

15 files changed

+162
-561
lines changed

dist/formly.js

Lines changed: 69 additions & 153 deletions
Large diffs are not rendered by default.

dist/formly.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/formly.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

other/ERRORS_AND_WARNINGS.md

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -127,53 +127,6 @@ of the expression, the scope you're passed wont have all the properties you may
127127
See documentation [here](http://docs.angular-formly.com/docs/field-configuration-object#hideexpression-string--function)
128128
and an example [here](http://angular-formly.com/#/example/field-options/hide-fields)
129129

130-
# Validators returning promises should use asyncValidators
131-
132-
Due to some issues with treating all function validators as async validators, the functionality has been split into
133-
simply `validators` and `asyncValidators`. The ability to return a promise from a validator has been deprecated and you
134-
should use `asyncValidators` for those now. For more info, see
135-
[#369](https://github.com/formly-js/angular-formly/issues/369).
136-
137-
# apiCheck as an object deprecated
138-
139-
As a performance optimization, the `apiCheck` property has been changed to a function. This is good because when
140-
apiCheck is disabled (either globally or the specified `apiCheckInstance`), the function is not even called which means
141-
the apiCheck checkers are never even created. Not much we can do about the couple of extra bytes, but that's not really
142-
a big issue. For more info, see [#334](https://github.com/formly-js/angular-formly/issues/334). Note, this will be
143-
removed in a major release.
144-
145-
# validateOptions deprecated
146-
147-
Because angular-formly already has a dependency on `api-check` and this is just a better way to validate your options,
148-
you should use this method instead. In an effort to simplify things. This has been deprecated in favor of the `apiCheck`
149-
property.
150-
151-
# skipNgModelAttrsManipulator moved
152-
153-
This property has been moved from the `data` property to the `extras` property.
154-
155-
Before:
156-
157-
```javascript
158-
{
159-
template: '<hr />',
160-
data: {
161-
skipNgModelAttrsManipulator: true
162-
}
163-
}
164-
```
165-
166-
After:
167-
168-
```javascript
169-
{
170-
template: '<hr />',
171-
extras: {
172-
skipNgModelAttrsManipulator: true
173-
}
174-
}
175-
```
176-
177130
# Notes
178131

179132
It is recommended to disable warnings in production using `formlyConfigProvider.disableWarnings = true`. Note: This will

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-formly",
3-
"version": "6.26.9",
3+
"version": "7.0.0",
44
"author": "Astrism <[email protected]>",
55
"contributors": [
66
"Astrism <[email protected]>",

src/directives/formly-custom-validation.js

Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ import angular from 'angular-fix';
22
export default formlyCustomValidation;
33

44
// @ngInject
5-
function formlyCustomValidation(formlyConfig, formlyUtil, $q, formlyWarn) {
5+
function formlyCustomValidation(formlyUtil) {
66
return {
77
restrict: 'A',
88
require: 'ngModel',
99
link: function formlyCustomValidationLink(scope, el, attrs, ctrl) {
1010
const opts = scope.options;
11-
const warnedValidators = [];
1211
opts.validation.messages = opts.validation.messages || {};
1312
angular.forEach(opts.validation.messages, (message, key) => {
1413
opts.validation.messages[key] = () => {
@@ -41,45 +40,18 @@ function formlyCustomValidation(formlyConfig, formlyUtil, $q, formlyWarn) {
4140
}
4241

4342
function setupWithValidators(validator, name, isAsync) {
44-
const isPossiblyAsync = !angular.isString(validator);
45-
let validatorCollection = (isPossiblyAsync || isAsync) ? '$asyncValidators' : '$validators';
46-
47-
// UPDATE IN 7.0.0
48-
// this is temporary until we can have a breaking change. Allow people to get the wins of the explicitAsync api
49-
if (formlyConfig.extras.explicitAsync && !isAsync) {
50-
validatorCollection = '$validators';
51-
}
43+
const validatorCollection = isAsync ? '$asyncValidators' : '$validators';
5244

5345
ctrl[validatorCollection][name] = function evalValidity(modelValue, viewValue) {
54-
const value = formlyUtil.formlyEval(scope, validator, modelValue, viewValue);
55-
// UPDATE IN 7.0.0
56-
// In the next breaking change, this code should simply return the value
57-
if (isAsync) {
58-
return value;
59-
} else if (isPossiblyAsync && !formlyConfig.extras.explicitAsync) {
60-
if (isPromiseLike(value)) {
61-
logAsyncValidatorsDeprecationNotice(validator, opts);
62-
return value;
63-
} else {
64-
return value ? $q.when(value) : $q.reject(value);
65-
}
66-
} else {
67-
return value;
68-
}
46+
return formlyUtil.formlyEval(scope, validator, modelValue, viewValue);
6947
};
7048
}
7149

7250
function setupWithParsers(validator, name, isAsync) {
7351
let inFlightValidator;
7452
ctrl.$parsers.unshift(function evalValidityOfParser(viewValue) {
7553
const isValid = formlyUtil.formlyEval(scope, validator, ctrl.$modelValue, viewValue);
76-
// UPDATE IN 7.0.0
77-
// In the next breaking change, rather than checking for isPromiseLike, it should just check for isAsync.
78-
79-
if (isAsync || isPromiseLike(isValid)) {
80-
if (!isAsync) {
81-
logAsyncValidatorsDeprecationNotice(validator, opts);
82-
}
54+
if (isAsync) {
8355
ctrl.$pending = ctrl.$pending || {};
8456
ctrl.$pending[name] = true;
8557
inFlightValidator = isValid;
@@ -105,24 +77,6 @@ function formlyCustomValidation(formlyConfig, formlyUtil, $q, formlyWarn) {
10577
return viewValue;
10678
});
10779
}
108-
109-
function logAsyncValidatorsDeprecationNotice(validator, options) {
110-
if (warnedValidators.indexOf(validator) !== -1) {
111-
// we've warned about this one before. No spam necessary...
112-
return;
113-
}
114-
warnedValidators.push(validator);
115-
formlyWarn(
116-
'validators-returning-promises-should-use-asyncvalidators',
117-
'Validators returning promises should use asyncValidators instead of validators.',
118-
options
119-
);
120-
}
12180
}
12281
};
123-
124-
125-
function isPromiseLike(obj) {
126-
return obj && angular.isFunction(obj.then);
127-
}
12882
}

src/directives/formly-custom-validation.test.js

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -30,37 +30,6 @@ describe(`formly-custom-validation`, function() {
3030
checkApi(formTemplate.replace(
3131
`TEMPLATE`, `<input ng-model="input" name="field" formly-custom-validation />`
3232
));
33-
34-
describe(`validators that are functions placement`, () => {
35-
it(`should be placed in $asyncValidators because it can return a promise`, () => {
36-
scope.options.validators.isHello = viewValue => viewValue === 'hello';
37-
$compile(
38-
`<form name="myForm"><input ng-model="input" name="field" formly-custom-validation /></form>`
39-
)(scope);
40-
scope.$digest();
41-
const field = scope.myForm.field;
42-
expect(field.$validators.isHello).to.not.exist;
43-
expect(field.$asyncValidators.isHello).to.exist;
44-
});
45-
46-
it(`should be placed in $validators if formlyConfig.extras.explicitAsync`, () => {
47-
formlyConfig.extras.explicitAsync = true;
48-
scope.options.validators.isHello = viewValue => viewValue === 'hello';
49-
$compile(
50-
`<form name="myForm"><input ng-model="input" name="field" formly-custom-validation /></form>`
51-
)(scope);
52-
scope.$digest();
53-
const field = scope.myForm.field;
54-
expect(field.$validators.isHello).to.exist;
55-
expect(field.$asyncValidators.isHello).to.not.exist;
56-
});
57-
58-
it(`should validate properly when explicitAsync is true`, () => {
59-
formlyConfig.extras.explicitAsync = true;
60-
const template = `<form name="myForm"><input ng-model="input" name="field" formly-custom-validation /></form>`;
61-
doValidation(template, 'hello', false, viewValue => viewValue !== 'hello', false);
62-
});
63-
});
6433
});
6534

6635
describe(`options.validation.messages`, () => {
@@ -100,18 +69,6 @@ describe(`formly-custom-validation`, function() {
10069
it(`should fail if it's a function that fails`, () => {
10170
validate(viewValue => viewValue !== value, false);
10271
});
103-
104-
it(`should warn if it's a function that returns a promise for a regular validator (should use asyncValidators instead)`, () => {
105-
const logArgs = [
106-
'Formly Warning:',
107-
'Validators returning promises should use asyncValidators instead of validators.',
108-
scope.options,
109-
/validators-returning-promises-should-use-asyncvalidators/
110-
];
111-
shouldWarnWithLog($log, logArgs, () => {
112-
validate(() => $q.when(), true);
113-
});
114-
});
11572
});
11673

11774
describe(`asyncValidators`, () => {

src/directives/formly-field.js

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,6 @@ function formlyField($http, $q, $compile, $templateCache, $interpolate, formlyCo
564564

565565
wrapper.forEach((aWrapper) => {
566566
formlyUsability.checkWrapper(aWrapper, options);
567-
aWrapper.validateOptions && aWrapper.validateOptions(options);
568567
runApiCheck(aWrapper, options);
569568
});
570569
const promises = wrapper.map(w => getTemplate(w.template || w.templateUrl, !w.template));
@@ -639,9 +638,6 @@ function formlyField($http, $q, $compile, $templateCache, $interpolate, formlyCo
639638
// validate with the type
640639
const type = options.type && formlyConfig.getType(options.type);
641640
if (type) {
642-
if (type.validateOptions) {
643-
type.validateOptions(options);
644-
}
645641
runApiCheck(type, options, true);
646642
}
647643
if (options.expressionProperties && options.expressionProperties.hide) {
@@ -679,26 +675,16 @@ function formlyField($http, $q, $compile, $templateCache, $interpolate, formlyCo
679675
return;
680676
}
681677
const fn = apiCheckFunction || 'warn';
682-
if (angular.isFunction(apiCheck)) {
683-
// this is the new API
684-
const checkerObjects = apiCheck(instance);
685-
angular.forEach(checkerObjects, (shape, name) => {
686-
const checker = instance.shape(shape);
687-
const checkOptions = angular.extend({
688-
prefix: `formly-field type ${options.type} for property ${name}`,
689-
url: formlyApiCheck.config.output.docsBaseUrl + 'formly-field-type-apicheck-failed'
690-
}, apiCheckOptions);
691-
instance[fn](checker, options[name], checkOptions);
692-
});
693-
} else {
694-
// TODO this is the deprecated API. Remove this in a breaking change.
695-
const checker = instance.shape(apiCheck);
696-
const checkOptions = apiCheckOptions || {
697-
prefix: `formly-field type ${options.type}`,
678+
// this is the new API
679+
const checkerObjects = apiCheck(instance);
680+
angular.forEach(checkerObjects, (shape, name) => {
681+
const checker = instance.shape(shape);
682+
const checkOptions = angular.extend({
683+
prefix: `formly-field type ${options.type} for property ${name}`,
698684
url: formlyApiCheck.config.output.docsBaseUrl + 'formly-field-type-apicheck-failed'
699-
};
700-
instance[fn](checker, options, checkOptions);
701-
}
685+
}, apiCheckOptions);
686+
instance[fn](checker, options[name], checkOptions);
687+
});
702688
}
703689

704690

src/directives/formly-field.test.js

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,12 @@ describe('formly-field', function() {
102102

103103

104104
describe('api check', () => {
105-
let validateOptions;
106105
beforeEach(() => {
107106
/* eslint no-console:0 */
108107
const originalWarn = console.warn;
109108
console.warn = () => {};
110-
validateOptions = sinon.spy();
111109
formlyConfig.setType({
112-
name: 'text', template: `<input name="{{id}}" ng-model="model[options.key]" />`,
113-
validateOptions
110+
name: 'text', template: `<input name="{{id}}" ng-model="model[options.key]" />`
114111
});
115112
scope.model = {};
116113
console.warn = originalWarn;
@@ -127,13 +124,6 @@ describe('formly-field', function() {
127124

128125
expect(() => compileAndDigest()).to.throw(/extra.*properties.*extraProp/);
129126
});
130-
131-
it(`should invoke the validateOptions property of the type`, () => {
132-
const field = {type: 'text'};
133-
scope.fields = [field];
134-
compileAndDigest();
135-
expect(validateOptions).to.have.been.calledWith(field);
136-
});
137127
});
138128

139129
describe('default type options', () => {
@@ -184,7 +174,7 @@ describe('formly-field', function() {
184174
attribute: 'required'
185175
},
186176
myChange: {
187-
expression: 'ng-change'
177+
statement: 'ng-change'
188178
}
189179
},
190180
templateOptions: {
@@ -632,28 +622,6 @@ describe('formly-field', function() {
632622
expect(type.apiCheck).to.have.been.calledWith(formlyApiCheck);
633623
}));
634624

635-
it(`should work with the old api`, () => {
636-
shouldWarn(
637-
/deprecated/,
638-
() => {
639-
formlyConfig.setType({
640-
name: 'someOtherType',
641-
template: '<label>{{to.label}}</label>',
642-
apiCheck: {
643-
templateOptions: apiCheck.shape({
644-
label: apiCheck.string
645-
})
646-
}
647-
});
648-
}
649-
);
650-
scope.fields = [{type: 'someOtherType'}];
651-
shouldWarn(
652-
/angular-formly: formly-field type someOtherType apiCheck failed.*?Required `label`.*?templateOptions.*?`String`/,
653-
compileAndDigest
654-
);
655-
});
656-
657625
it(`should not warn if everything's fine`, () => {
658626
scope.fields = [
659627
{type, templateOptions: {label: 'string', className: 'string'}}

src/other/utils.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import angular from 'angular-fix';
22

3-
export default {formlyEval, getFieldId, reverseDeepMerge, findByNodeName, arrayify, extendFunction, extendArray, startsWith};
3+
export default {
4+
formlyEval, getFieldId, reverseDeepMerge, findByNodeName, arrayify, extendFunction, extendArray, startsWith, contains
5+
};
46

57
function formlyEval(scope, expression, $modelValue, $viewValue, extraLocals) {
68
if (angular.isFunction(expression)) {
@@ -109,3 +111,11 @@ function startsWith(str, search) {
109111
return false;
110112
}
111113
}
114+
115+
function contains(str, search) {
116+
if (angular.isString(str) && angular.isString(search)) {
117+
return str.length >= search.length && str.indexOf(search) !== -1;
118+
} else {
119+
return false;
120+
}
121+
}

0 commit comments

Comments
 (0)