@@ -189,7 +189,7 @@ angular.module('schemaForm').provider('schemaFormDecorators',
189
189
// Do we have a condition? Then we slap on an ng-if on all children,
190
190
// but be nice to existing ng-if.
191
191
if ( form . condition ) {
192
- angular . forEach ( element . children ( ) , function ( child ) {
192
+ angular . forEach ( element . children ( ) , function ( child ) {
193
193
var ngIf = child . getAttribute ( 'ng-if' ) ;
194
194
child . setAttribute (
195
195
'ng-if' ,
@@ -204,6 +204,45 @@ angular.module('schemaForm').provider('schemaFormDecorators',
204
204
$compile ( element . contents ( ) ) ( scope ) ;
205
205
} ) ;
206
206
207
+ // Where there is a key there is probably a ngModel
208
+ if ( form . key ) {
209
+ // It looks better with dot notation.
210
+ scope . $on (
211
+ 'schemaForm.error.' + form . key . join ( '.' ) ,
212
+ function ( event , error , validationMessage , validity ) {
213
+ if ( validationMessage === true || validationMessage === false ) {
214
+ validity = validationMessage ;
215
+ validationMessage = undefined ;
216
+ }
217
+
218
+ if ( scope . ngModel && error ) {
219
+ if ( scope . ngModel . $setDirty ( ) ) {
220
+ scope . ngModel . $setDirty ( ) ;
221
+ } else {
222
+ // FIXME: Check that this actually works on 1.2
223
+ scope . ngModel . $dirty = true ;
224
+ scope . ngModel . $pristine = false ;
225
+ }
226
+
227
+ // Set the new validation message if one is supplied
228
+ // Does not work when validationMessage is just a string.
229
+ if ( validationMessage ) {
230
+ if ( ! form . validationMessage ) {
231
+ form . validationMessage = { } ;
232
+ }
233
+ console . log ( 'settings validationMessage' , validationMessage )
234
+ form . validationMessage [ error ] = validationMessage ;
235
+ }
236
+
237
+ scope . ngModel . $setValidity ( error , validity === true ) ;
238
+
239
+ // Setting or removing a validity can change the field to believe its valid
240
+ // but its not. So lets trigger its validation as well.
241
+ scope . $broadcast ( 'schemaFormValidate' ) ;
242
+ }
243
+ } )
244
+ }
245
+
207
246
once ( ) ;
208
247
}
209
248
} ) ;
0 commit comments