@@ -65,81 +65,6 @@ angular.module('schemaForm').provider('sfPath',
65
65
} ;
66
66
} ] ) ;
67
67
68
- /**
69
- * @ngdoc service
70
- * @name sfSelect
71
- * @kind function
72
- *
73
- */
74
- angular . module ( 'schemaForm' ) . factory ( 'sfSelect' , [ 'sfPath' , function ( sfPath ) {
75
- var numRe = / ^ \d + $ / ;
76
-
77
- /**
78
- * @description
79
- * Utility method to access deep properties without
80
- * throwing errors when things are not defined.
81
- * Can also set a value in a deep structure, creating objects when missing
82
- * ex.
83
- * var foo = Select('address.contact.name',obj)
84
- * Select('address.contact.name',obj,'Leeroy')
85
- *
86
- * @param {string } projection A dot path to the property you want to get/set
87
- * @param {object } obj (optional) The object to project on, defaults to 'this'
88
- * @param {Any } valueToSet (opional) The value to set, if parts of the path of
89
- * the projection is missing empty objects will be created.
90
- * @returns {Any|undefined } returns the value at the end of the projection path
91
- * or undefined if there is none.
92
- */
93
- return function ( projection , obj , valueToSet ) {
94
- if ( ! obj ) {
95
- obj = this ;
96
- }
97
- //Support [] array syntax
98
- var parts = typeof projection === 'string' ? sfPath . parse ( projection ) : projection ;
99
-
100
- if ( typeof valueToSet !== 'undefined' && parts . length === 1 ) {
101
- //special case, just setting one variable
102
- obj [ parts [ 0 ] ] = valueToSet ;
103
- return obj ;
104
- }
105
-
106
- if ( typeof valueToSet !== 'undefined' &&
107
- typeof obj [ parts [ 0 ] ] === 'undefined' ) {
108
- // We need to look ahead to check if array is appropriate
109
- obj [ parts [ 0 ] ] = parts . length > 2 && numRe . test ( parts [ 1 ] ) ? [ ] : { } ;
110
- }
111
-
112
- var value = obj [ parts [ 0 ] ] ;
113
- for ( var i = 1 ; i < parts . length ; i ++ ) {
114
- // Special case: We allow JSON Form syntax for arrays using empty brackets
115
- // These will of course not work here so we exit if they are found.
116
- if ( parts [ i ] === '' ) {
117
- return undefined ;
118
- }
119
- if ( typeof valueToSet !== 'undefined' ) {
120
- if ( i === parts . length - 1 ) {
121
- //last step. Let's set the value
122
- value [ parts [ i ] ] = valueToSet ;
123
- return valueToSet ;
124
- } else {
125
- // Make sure to create new objects on the way if they are not there.
126
- // We need to look ahead to check if array is appropriate
127
- var tmp = value [ parts [ i ] ] ;
128
- if ( typeof tmp === 'undefined' || tmp === null ) {
129
- tmp = numRe . test ( parts [ i + 1 ] ) ? [ ] : { } ;
130
- value [ parts [ i ] ] = tmp ;
131
- }
132
- value = tmp ;
133
- }
134
- } else if ( value ) {
135
- //Just get nex value.
136
- value = value [ parts [ i ] ] ;
137
- }
138
- }
139
- return value ;
140
- } ;
141
- } ] ) ;
142
-
143
68
144
69
// FIXME: type template (using custom builder)
145
70
angular . module ( 'schemaForm' ) . provider ( 'sfBuilder' , [ 'sfPathProvider' , function ( sfPathProvider ) {
@@ -682,6 +607,9 @@ angular.module('schemaForm').provider('schemaFormDecorators',
682
607
scope . ngModel . $setValidity ( error , validity === true ) ;
683
608
684
609
if ( validity === true ) {
610
+ // Re-trigger model validator, that model itself would be re-validated
611
+ scope . ngModel . $validate ( ) ;
612
+
685
613
// Setting or removing a validity can change the field to believe its valid
686
614
// but its not. So lets trigger its validation as well.
687
615
scope . $broadcast ( 'schemaFormValidate' ) ;
@@ -1553,6 +1481,81 @@ angular.module('schemaForm').provider('schemaForm',
1553
1481
1554
1482
} ] ) ;
1555
1483
1484
+ /**
1485
+ * @ngdoc service
1486
+ * @name sfSelect
1487
+ * @kind function
1488
+ *
1489
+ */
1490
+ angular . module ( 'schemaForm' ) . factory ( 'sfSelect' , [ 'sfPath' , function ( sfPath ) {
1491
+ var numRe = / ^ \d + $ / ;
1492
+
1493
+ /**
1494
+ * @description
1495
+ * Utility method to access deep properties without
1496
+ * throwing errors when things are not defined.
1497
+ * Can also set a value in a deep structure, creating objects when missing
1498
+ * ex.
1499
+ * var foo = Select('address.contact.name',obj)
1500
+ * Select('address.contact.name',obj,'Leeroy')
1501
+ *
1502
+ * @param {string } projection A dot path to the property you want to get/set
1503
+ * @param {object } obj (optional) The object to project on, defaults to 'this'
1504
+ * @param {Any } valueToSet (opional) The value to set, if parts of the path of
1505
+ * the projection is missing empty objects will be created.
1506
+ * @returns {Any|undefined } returns the value at the end of the projection path
1507
+ * or undefined if there is none.
1508
+ */
1509
+ return function ( projection , obj , valueToSet ) {
1510
+ if ( ! obj ) {
1511
+ obj = this ;
1512
+ }
1513
+ //Support [] array syntax
1514
+ var parts = typeof projection === 'string' ? sfPath . parse ( projection ) : projection ;
1515
+
1516
+ if ( typeof valueToSet !== 'undefined' && parts . length === 1 ) {
1517
+ //special case, just setting one variable
1518
+ obj [ parts [ 0 ] ] = valueToSet ;
1519
+ return obj ;
1520
+ }
1521
+
1522
+ if ( typeof valueToSet !== 'undefined' &&
1523
+ typeof obj [ parts [ 0 ] ] === 'undefined' ) {
1524
+ // We need to look ahead to check if array is appropriate
1525
+ obj [ parts [ 0 ] ] = parts . length > 2 && numRe . test ( parts [ 1 ] ) ? [ ] : { } ;
1526
+ }
1527
+
1528
+ var value = obj [ parts [ 0 ] ] ;
1529
+ for ( var i = 1 ; i < parts . length ; i ++ ) {
1530
+ // Special case: We allow JSON Form syntax for arrays using empty brackets
1531
+ // These will of course not work here so we exit if they are found.
1532
+ if ( parts [ i ] === '' ) {
1533
+ return undefined ;
1534
+ }
1535
+ if ( typeof valueToSet !== 'undefined' ) {
1536
+ if ( i === parts . length - 1 ) {
1537
+ //last step. Let's set the value
1538
+ value [ parts [ i ] ] = valueToSet ;
1539
+ return valueToSet ;
1540
+ } else {
1541
+ // Make sure to create new objects on the way if they are not there.
1542
+ // We need to look ahead to check if array is appropriate
1543
+ var tmp = value [ parts [ i ] ] ;
1544
+ if ( typeof tmp === 'undefined' || tmp === null ) {
1545
+ tmp = numRe . test ( parts [ i + 1 ] ) ? [ ] : { } ;
1546
+ value [ parts [ i ] ] = tmp ;
1547
+ }
1548
+ value = tmp ;
1549
+ }
1550
+ } else if ( value ) {
1551
+ //Just get nex value.
1552
+ value = value [ parts [ i ] ] ;
1553
+ }
1554
+ }
1555
+ return value ;
1556
+ } ;
1557
+ } ] ) ;
1558
+
1556
1559
/* Common code for validating a value against its form and schema definition */
1557
1560
/* global tv4 */
1558
1561
angular . module ( 'schemaForm' ) . factory ( 'sfValidator' , [ function ( ) {
@@ -2109,6 +2112,9 @@ angular.module('schemaForm').directive('sfField',
2109
2112
scope . ngModel . $setValidity ( error , validity === true ) ;
2110
2113
2111
2114
if ( validity === true ) {
2115
+ // Re-trigger model validator, that model itself would be re-validated
2116
+ scope . ngModel . $validate ( ) ;
2117
+
2112
2118
// Setting or removing a validity can change the field to believe its valid
2113
2119
// but its not. So lets trigger its validation as well.
2114
2120
scope . $broadcast ( 'schemaFormValidate' ) ;
@@ -2677,7 +2683,7 @@ angular.module('schemaForm')
2677
2683
// part of the form or schema is chnaged without it being a new instance.
2678
2684
scope . $on ( 'schemaFormRedraw' , function ( ) {
2679
2685
var schema = scope . schema ;
2680
- var form = scope . initialForm || [ '*' ] ;
2686
+ var form = scope . initialForm ? angular . copy ( scope . initialForm ) : [ '*' ] ;
2681
2687
if ( schema ) {
2682
2688
render ( schema , form ) ;
2683
2689
}
@@ -2817,7 +2823,13 @@ angular.module('schemaForm').directive('schemaValidate', ['sfValidator', '$parse
2817
2823
var schema = form . schema ;
2818
2824
2819
2825
// A bit ugly but useful.
2820
- scope . validateField = function ( ) {
2826
+ scope . validateField = function ( formName ) {
2827
+
2828
+ // If we have specified a form name, and this model is not within
2829
+ // that form, then leave things be.
2830
+ if ( formName != undefined && ngModel . $$parentForm . $name !== formName ) {
2831
+ return ;
2832
+ }
2821
2833
2822
2834
// Special case: arrays
2823
2835
// TODO: Can this be generalized in a way that works consistently?
@@ -2864,7 +2876,9 @@ angular.module('schemaForm').directive('schemaValidate', ['sfValidator', '$parse
2864
2876
} ) ;
2865
2877
2866
2878
// Listen to an event so we can validate the input on request
2867
- scope . $on ( 'schemaFormValidate' , scope . validateField ) ;
2879
+ scope . $on ( 'schemaFormValidate' , function ( event , formName ) {
2880
+ scope . validateField ( formName ) ;
2881
+ } ) ;
2868
2882
2869
2883
scope . schemaError = function ( ) {
2870
2884
return error ;
0 commit comments