Skip to content

Commit 46be726

Browse files
committed
added template options
1 parent 287c1b2 commit 46be726

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/components/FormlyField.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<template>
2-
<component :is="type" :form.sync="form" :field="field" :model="model"></component>
2+
<component :is="type" :form.sync="form" :field="field" :model="model" :to="field.templateOptions"></component>
33
</template>
44

55
<script>
66
const Vue = require('vue');
77
import Util, {getTypes, setError} from '../util';
88
export default {
9-
props: ['form', 'model', 'field'],
9+
props: ['form', 'model', 'field', 'to'],
1010
computed: {
1111
type:function(){
1212
return 'formly_'+this.field.type;
@@ -17,6 +17,7 @@
1717
1818
//first check if we need to create a field
1919
if ( !this.form.$errors[this.field.key] ) this.$set(this.form.$errors, this.field.key, {});
20+
if ( !this.field.templateOptions ) this.$set(this.field, 'templateOptions', {});
2021
2122
//check for required fields. This whole setting,unsetting thing seems kind of wrong though..
2223
//there might be a more 'vue-ey' way to do this...

test/unit/specs/FormlyField.spec.js

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

9191
});
9292

93+
it('Should pass template options', () => {
94+
95+
Vue.component('formly_test', {
96+
props: ['form', 'field', 'model', 'to'],
97+
template: '<div>{{to}}</div>'
98+
});
99+
100+
let data = {
101+
form: {
102+
$errors: {},
103+
$valid: {}
104+
},
105+
fields: [
106+
{
107+
key: 'search',
108+
type: 'test',
109+
templateOptions: {
110+
foo: 'bar',
111+
something: 'else'
112+
}
113+
}
114+
],
115+
model: {
116+
search: ''
117+
}
118+
};
119+
120+
createForm('<formly-field :form.sync="form" :field="fields[0]" :model="model"></formly-field>', data);
121+
122+
expect(JSON.parse(vm.$el.textContent)).to.deep.equal(data.fields[0].templateOptions);
123+
124+
});
125+
93126

94127
describe('Validation', ()=>{
95128

0 commit comments

Comments
 (0)