@@ -65,6 +65,81 @@ 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
+
68
143
69
144
// FIXME: type template (using custom builder)
70
145
angular . module ( 'schemaForm' ) . provider ( 'sfBuilder' , [ 'sfPathProvider' , function ( sfPathProvider ) {
@@ -1481,81 +1556,6 @@ angular.module('schemaForm').provider('schemaForm',
1481
1556
1482
1557
} ] ) ;
1483
1558
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
-
1559
1559
/* Common code for validating a value against its form and schema definition */
1560
1560
/* global tv4 */
1561
1561
angular . module ( 'schemaForm' ) . factory ( 'sfValidator' , [ function ( ) {
@@ -2852,8 +2852,8 @@ angular.module('schemaForm').directive('schemaValidate', ['sfValidator', '$parse
2852
2852
2853
2853
// In Angular 1.3 setting undefined as a viewValue does not trigger parsers
2854
2854
// so we need to do a special required check. Fortunately we have $isEmpty
2855
- if ( form . required && ngModel . $isEmpty ( ngModel . $modelValue ) ) {
2856
- ngModel . $setValidity ( 'tv4-302' , false ) ;
2855
+ if ( ngModel . $isEmpty ( ngModel . $modelValue ) ) {
2856
+ ngModel . $setValidity ( 'tv4-302' , ! form . required ) ;
2857
2857
}
2858
2858
2859
2859
} else {
0 commit comments