Skip to content

Commit 7f71a00

Browse files
committed
defaulting template options
1 parent aa16efc commit 7f71a00

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/components/FormlyField.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ export default {
77
form: this.form,
88
field: this.field,
99
model: this.model,
10-
to: this.field.templateOptions
10+
to: this.templateOptions
1111
}
1212
});
1313
},
1414
props: ['form', 'model', 'field', 'to'],
1515
computed: {
16+
templateOptions: function(){
17+
return this.field.templateOptions || {};
18+
},
1619
type:function(){
1720
return 'formly_'+this.field.type;
1821
},

test/unit/specs/FormlyField.spec.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,33 @@ describe('FormlyField', () => {
127127

128128
});
129129

130+
it('Should default {} to templateOptions if none are defined', () => {
131+
Vue.component('formly_test', {
132+
props: ['form', 'field', 'model', 'to'],
133+
template: '<div></div>'
134+
});
135+
136+
let data = {
137+
form: {
138+
$errors: {},
139+
$valid: {}
140+
},
141+
fields: [
142+
{
143+
key: 'search',
144+
type: 'test'
145+
}
146+
],
147+
model: {
148+
search: ''
149+
}
150+
};
151+
152+
createForm('<formly-field ref="formlyField" :form.sync="form" :field="fields[0]" :model="model"></formly-field>', data);
153+
154+
expect(vm.$refs.formlyField.templateOptions).to.deep.equal({});
155+
});
156+
130157
it('Should take a wrapper string', () => {
131158
Vue.component('formly_test', {
132159
props: ['form', 'field', 'model', 'to'],

0 commit comments

Comments
 (0)