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

Commit 8a542d5

Browse files
author
Kent C. Dodds
committed
Merge pull request #529 from benoror/master
feat(fieldGroup): allow wrapper & templateOptions
2 parents 34015c7 + f40bd6c commit 8a542d5

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

src/directives/formly-field.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ function formlyField($http, $q, $compile, $templateCache, $interpolate, formlyCo
258258
if (scope.options.key) {
259259
modelValue = `model['${scope.options.key}']`
260260
}
261-
setElementTemplate(`
261+
getTemplate(`
262262
<formly-form model="${modelValue}"
263263
fields="options.fieldGroup"
264264
options="options.options"
@@ -268,6 +268,8 @@ function formlyField($http, $q, $compile, $templateCache, $interpolate, formlyCo
268268
is-field-group>
269269
</formly-form>
270270
`)
271+
.then(transcludeInWrappers(scope.options, scope.formOptions))
272+
.then(setElementTemplate)
271273
}
272274

273275
function addAttributes() {

src/directives/formly-form.test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,48 @@ describe('formly-form', () => {
280280
})
281281
})
282282

283+
it(`should be possible to use a wrapper & templateOptions in a fieldGroup`, () => {
284+
formlyConfig.setWrapper({
285+
name: 'panel',
286+
template: `<div class="panel">
287+
<div class="heading">
288+
Panel Title: {{options.templateOptions.title}}
289+
</div>
290+
<div class="body">
291+
<formly-transclude></formly-transclude>
292+
</div>
293+
</div>
294+
`,
295+
})
296+
297+
scope.fields = [
298+
{
299+
className: 'field-group',
300+
wrapper: 'panel',
301+
templateOptions: {
302+
title: 'My Panel',
303+
},
304+
fieldGroup: [
305+
getNewField(),
306+
getNewField(),
307+
],
308+
},
309+
]
310+
311+
scope.options = {}
312+
313+
compileAndDigest()
314+
315+
const panelNode = el[0].querySelector('.panel')
316+
expect(panelNode).to.exist
317+
const bodyNode = panelNode.querySelector('.body')
318+
expect(bodyNode).to.exist
319+
const headingNode = panelNode.querySelector('.heading')
320+
expect(headingNode).to.exist
321+
const headingEl = angular.element(headingNode)
322+
expect(headingEl.text().trim()).to.eq('Panel Title: My Panel')
323+
})
324+
283325
it(`should be possible to hide a fieldGroup with the hide property`, () => {
284326
compileAndDigest()
285327

src/providers/formlyApiCheck.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ const fieldGroup = apiCheck.shape({
179179
fieldGroup: apiCheck.arrayOf(apiCheck.oneOfType([formlyFieldOptions, apiCheck.object])),
180180
className: apiCheck.string.optional,
181181
options: formOptionsApi.optional,
182+
templateOptions: apiCheck.object.optional,
183+
wrapper: specifyWrapperType.optional,
182184
hide: apiCheck.bool.optional,
183185
hideExpression: formlyExpression.optional,
184186
data: apiCheck.object.optional,

0 commit comments

Comments
 (0)