@@ -269,8 +269,10 @@ describe('FormlyField', () => {
269
269
key : 'search' ,
270
270
type : 'test' ,
271
271
validators : {
272
- expression : function ( field , model ) {
273
- return model . search == 'test' ;
272
+ expression : function ( field , model , next ) {
273
+ let valid = model . search == 'test' ;
274
+ next ( valid ) ;
275
+ //return model.search == 'test';
274
276
}
275
277
}
276
278
}
@@ -286,6 +288,43 @@ describe('FormlyField', () => {
286
288
} , 0 ) ;
287
289
} ) ;
288
290
291
+ it ( 'Async Validation' , ( done ) => {
292
+ let data = {
293
+ form : {
294
+ $valid : true ,
295
+ $errors : { }
296
+ } ,
297
+ model : {
298
+ search : 'testing'
299
+ } ,
300
+ fields : [
301
+ {
302
+ key : 'search' ,
303
+ type : 'test' ,
304
+ validators : {
305
+ asyncExpression : function ( field , model , next ) {
306
+ console . log ( '--- first timeout here' ) ;
307
+ let valid = model . search == 'test' ;
308
+ setTimeout ( function ( ) {
309
+ console . log ( '--------------- timeout here' ) ;
310
+ next ( valid ) ;
311
+ } , 500 ) ;
312
+ }
313
+ }
314
+ }
315
+ ]
316
+ } ;
317
+
318
+ createValidField ( data ) ;
319
+ console . log ( 'expression is ' , vm . form . $errors . search . asyncExpression ) ;
320
+ expect ( vm . form . $errors . search . asyncExpression ) . to . be . true ;
321
+ vm . model . search = 'test' ;
322
+ setTimeout ( ( ) => {
323
+ //expect(vm.form.$errors.search.expression).to.be.false;
324
+ //done();
325
+ } , 1000 ) ;
326
+ } ) ;
327
+
289
328
describe ( "Validation Messages" , ( done ) => {
290
329
291
330
//what do we want to do
@@ -331,6 +370,37 @@ describe('FormlyField', () => {
331
370
expect ( vm . form . $errors . search . validatorMessage ) . to . equal ( 'Must equal test' ) ;
332
371
} ) ;
333
372
373
+ it ( 'Inline messages with a function' , ( ) => {
374
+ let data = {
375
+ form : {
376
+ $valid : true ,
377
+ $errors : { }
378
+ } ,
379
+ model : {
380
+ search : 'testing'
381
+ } ,
382
+ fields : [
383
+ {
384
+ key : 'search' ,
385
+ type : 'test' ,
386
+ validators : {
387
+ validatorMessage :
388
+ {
389
+ expression : function ( field , model , next ) {
390
+ let valid = model . search == "test" ;
391
+ next ( valid ) ;
392
+ } ,
393
+ message : 'Must equal test'
394
+ }
395
+ }
396
+ }
397
+ ]
398
+ } ;
399
+
400
+ createValidField ( data ) ;
401
+ expect ( vm . form . $errors . search . validatorMessage ) . to . equal ( 'Must equal test' ) ;
402
+ } ) ;
403
+
334
404
it ( 'Inline messages with values parsed' , ( ) => {
335
405
let data = {
336
406
form : {
0 commit comments