Skip to content

Commit ee7b920

Browse files
committed
moving validation updates to promises
1 parent 97eef09 commit ee7b920

File tree

2 files changed

+19
-24
lines changed

2 files changed

+19
-24
lines changed

src/components/FormlyForm.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ export default {
1414
let count = 0;
1515
this.fields.forEach( field => {
1616
this.$set( this.form[ field.key ], '$dirty', true );
17-
console.log(this.$refs[ field.key ][0]);
18-
//this.$refs[ field.key ][0].validate();
17+
this.$refs[ field.key ][0].validate()
18+
.then(()=>{
19+
count++;
20+
if( target == count ) resolve();
21+
});
1922
});
20-
resolve();
2123
});
2224
}
2325
},

test/unit/specs/FormlyForm.spec.js

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -166,45 +166,38 @@ describe('FormlyForm', () => {
166166
form: {
167167
validTest: {
168168
$dirty: false
169+
},
170+
validTest2: {
171+
$dirty: false
169172
}
170173
},
171-
model: {validTest:''},
174+
model: {validTest:'', validTest2: ''},
172175
fields: [{
173176
key: 'validTest',
174177
type: 'input'
175-
}]
178+
},
179+
{
180+
key: 'validTest2',
181+
type: 'input'
182+
}]
176183
};
177184

178185
el = document.createElement('DIV');
179186
document.body.appendChild(el);
187+
Vue.component('formly-field', ValidField);
180188
vm = new Vue({
181189
data: data,
182-
template: '<formly-form :form="form" :model="model" :fields="fields"></formly-form>',
183-
components: {
184-
'formly-field': ValidField
185-
}
190+
template: '<formly-form :form="form" :model="model" :fields="fields"></formly-form>'
186191
}).$mount(el);
187192

188193

189194
let spy = sinon.spy();
190195

191196
let prom = vm.$children[0].validate();
192-
prom.then(()=>{
193-
console.log('prom.then');
194-
})
195-
.catch((e)=>{
196-
console.log('prom.catch', e);
197-
});
198-
return done();
199-
expect(typeof prom.then).to.equal('function');
200-
prom
201-
.then(()=>spy())
202-
.catch(()=>{
203-
204-
});
205-
return done();
197+
prom.then(()=>spy());
206198
setTimeout(()=>{
207-
spy.should.be.called;
199+
spy.should.be.calledOnce;
200+
formlyFieldSpy.should.be.calledTwice;
208201
done();
209202
});
210203
});

0 commit comments

Comments
 (0)