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

Commit a4c54bb

Browse files
seibsKent C. Dodds
authored and
Kent C. Dodds
committedMay 15, 2016
fix(formlyConfig): fix defaultOptions override behavior (#680)
Fix the override behavior when the extended type's defaultOptions field is defined as a function. Closes #635
1 parent 3bd8ec0 commit a4c54bb

File tree

2 files changed

+65
-3
lines changed

2 files changed

+65
-3
lines changed
 

Diff for: ‎src/providers/formlyConfig.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ function formlyConfig(formlyUsabilityProvider, formlyErrorAndWarningsUrlPrefix,
124124
if (!angular.isDefined(extendsDO)) {
125125
return
126126
}
127-
const optionsDO = options.defaultOptions
127+
const optionsDO = options.defaultOptions || {}
128128
const optionsDOIsFn = angular.isFunction(optionsDO)
129129
const extendsDOIsFn = angular.isFunction(extendsDO)
130130
if (extendsDOIsFn) {
@@ -136,8 +136,8 @@ function formlyConfig(formlyUsabilityProvider, formlyErrorAndWarningsUrlPrefix,
136136
if (optionsDOIsFn) {
137137
extenderOptionsDefaultOptions = extenderOptionsDefaultOptions(mergedDefaultOptions, scope)
138138
}
139-
utils.reverseDeepMerge(extendsDefaultOptions, extenderOptionsDefaultOptions)
140-
return extendsDefaultOptions
139+
utils.reverseDeepMerge(extenderOptionsDefaultOptions, extendsDefaultOptions)
140+
return extenderOptionsDefaultOptions
141141
}
142142
} else if (optionsDOIsFn) {
143143
options.defaultOptions = function defaultOptions(opts, scope) {

Diff for: ‎src/providers/formlyConfig.test.js

+62
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,68 @@ describe('formlyConfig', () => {
287287
})
288288

289289
})
290+
291+
describe(`abstractType function case`, () => {
292+
beforeEach(() => {
293+
setterFn([
294+
{
295+
name,
296+
template,
297+
defaultOptions: function(options) {
298+
return {
299+
templateOptions: {
300+
required: true,
301+
min: 3,
302+
},
303+
}
304+
},
305+
},
306+
{
307+
name: 'type2',
308+
extends: name,
309+
defaultOptions: function(options) {
310+
return {
311+
templateOptions: {
312+
required: false,
313+
max: 4,
314+
},
315+
}
316+
},
317+
},
318+
{
319+
name: 'type3',
320+
extends: name,
321+
defaultOptions: {
322+
templateOptions: {
323+
required: false,
324+
max: 4,
325+
},
326+
},
327+
},
328+
])
329+
})
330+
331+
it(`should merge options when extending defaultOptions is a function`, () => {
332+
expect(getterFn('type2').defaultOptions({})).to.eql({
333+
templateOptions: {
334+
required: false,
335+
min: 3,
336+
max: 4,
337+
},
338+
})
339+
})
340+
341+
it(`should merge options when extending defaultOptions is an object`, () => {
342+
expect(getterFn('type3').defaultOptions({})).to.eql({
343+
templateOptions: {
344+
required: false,
345+
min: 3,
346+
max: 4,
347+
},
348+
})
349+
})
350+
351+
})
290352

291353
describe(`template/templateUrl Cases`, () => {
292354
it('should use templateUrl if type defines it and its parent has template defined', function() {

0 commit comments

Comments
 (0)