@@ -317,7 +317,7 @@ angular.module('schemaForm').provider('schemaFormDecorators',
317
317
// Do we have a condition? Then we slap on an ng-if on all children,
318
318
// but be nice to existing ng-if.
319
319
if ( form . condition ) {
320
- angular . forEach ( element . children ( ) , function ( child ) {
320
+ angular . forEach ( element . children ( ) , function ( child ) {
321
321
var ngIf = child . getAttribute ( 'ng-if' ) ;
322
322
child . setAttribute (
323
323
'ng-if' ,
@@ -332,6 +332,45 @@ angular.module('schemaForm').provider('schemaFormDecorators',
332
332
$compile ( element . contents ( ) ) ( scope ) ;
333
333
} ) ;
334
334
335
+ // Where there is a key there is probably a ngModel
336
+ if ( form . key ) {
337
+ // It looks better with dot notation.
338
+ scope . $on (
339
+ 'schemaForm.error.' + form . key . join ( '.' ) ,
340
+ function ( event , error , validationMessage , validity ) {
341
+ if ( validationMessage === true || validationMessage === false ) {
342
+ validity = validationMessage ;
343
+ validationMessage = undefined ;
344
+ }
345
+
346
+ if ( scope . ngModel && error ) {
347
+ if ( scope . ngModel . $setDirty ( ) ) {
348
+ scope . ngModel . $setDirty ( ) ;
349
+ } else {
350
+ // FIXME: Check that this actually works on 1.2
351
+ scope . ngModel . $dirty = true ;
352
+ scope . ngModel . $pristine = false ;
353
+ }
354
+
355
+ // Set the new validation message if one is supplied
356
+ // Does not work when validationMessage is just a string.
357
+ if ( validationMessage ) {
358
+ if ( ! form . validationMessage ) {
359
+ form . validationMessage = { } ;
360
+ }
361
+ console . log ( 'settings validationMessage' , validationMessage )
362
+ form . validationMessage [ error ] = validationMessage ;
363
+ }
364
+
365
+ scope . ngModel . $setValidity ( error , validity === true ) ;
366
+
367
+ // Setting or removing a validity can change the field to believe its valid
368
+ // but its not. So lets trigger its validation as well.
369
+ scope . $broadcast ( 'schemaFormValidate' ) ;
370
+ }
371
+ } )
372
+ }
373
+
335
374
once ( ) ;
336
375
}
337
376
} ) ;
@@ -1710,8 +1749,7 @@ angular.module('schemaForm').directive('schemaValidate', ['sfValidator', 'sfSele
1710
1749
if ( ngModel . $setDirty ( ) ) {
1711
1750
ngModel . $setDirty ( ) ;
1712
1751
}
1713
- validate ( ) ;
1714
- //}
1752
+ validate ( ngModel . $viewValue ) ;
1715
1753
} ) ;
1716
1754
1717
1755
scope . schemaError = function ( ) {
0 commit comments