@@ -14,25 +14,25 @@ angular.module('schemaForm').provider('sfErrorMessage', function() {
1414 12 : 'Data is valid against more than one schema from "oneOf"' ,
1515 13 : 'Data matches schema from "not"' ,
1616 // Numeric errors
17- 100 : 'Value {{value}} is not a multiple of {{schema.multipleOf }}' ,
18- 101 : 'Value {{value }} is less than minimum {{schema.minimum}}' ,
19- 102 : 'Value {{value }} is equal to exclusive minimum {{schema.minimum}}' ,
20- 103 : 'Value {{value }} is greater than maximum {{schema.maximum}}' ,
21- 104 : 'Value {{value }} is equal to exclusive maximum {{schema.maximum}}' ,
22- 105 : 'Value {{value}} is not a valid number' ,
17+ 100 : 'Value is not a multiple of {{schema.divisibleBy }}' ,
18+ 101 : '{{viewValue }} is less than the allowed minimum of {{schema.minimum}}' ,
19+ 102 : '{{viewValue }} is equal to the exclusive minimum {{schema.minimum}}' ,
20+ 103 : '{{viewValue }} is greater than the allowed maximum of {{schema.maximum}}' ,
21+ 104 : '{{viewValue }} is equal to the exclusive maximum {{schema.maximum}}' ,
22+ 105 : 'Value is not a valid number' ,
2323 // String errors
24- 200 : 'String is too short ({{value .length}} chars), minimum {{schema.minimum }}' ,
25- 201 : 'String is too long ({{value .length}} chars), maximum {{schema.maximum }}' ,
24+ 200 : 'String is too short ({{viewValue .length}} chars), minimum {{schema.minLength }}' ,
25+ 201 : 'String is too long ({{viewValue .length}} chars), maximum {{schema.maxLength }}' ,
2626 202 : 'String does not match pattern: {{schema.pattern}}' ,
2727 // Object errors
28- 300 : 'Too few properties defined, minimum {{schema.minimum }}' ,
29- 301 : 'Too many properties defined, maximum {{schema.maximum }}' ,
28+ 300 : 'Too few properties defined, minimum {{schema.minProperties }}' ,
29+ 301 : 'Too many properties defined, maximum {{schema.maxProperties }}' ,
3030 302 : 'Required' ,
3131 303 : 'Additional properties not allowed' ,
3232 304 : 'Dependency failed - key must exist' ,
3333 // Array errors
34- 400 : 'Array is too short ({{value.length}}), minimum {{schema.minimum }}' ,
35- 401 : 'Array is too long ({{value.length}}), maximum {{schema.maximum }}' ,
34+ 400 : 'Array is too short ({{value.length}}), minimum {{schema.maxItems }}' ,
35+ 401 : 'Array is too long ({{value.length}}), maximum {{schema.minItems }}' ,
3636 402 : 'Array items are not unique' ,
3737 403 : 'Additional items not allowed' ,
3838 // Format errors
@@ -44,6 +44,15 @@ angular.module('schemaForm').provider('sfErrorMessage', function() {
4444 1000 : 'Unknown property (not in schema)'
4545 } ;
4646
47+ // In some cases we get hit with an angular validation error
48+ defaultMessages . number = defaultMessages [ 105 ] ;
49+ defaultMessages . required = defaultMessages [ 302 ] ;
50+ defaultMessages . min = defaultMessages [ 101 ] ;
51+ defaultMessages . max = defaultMessages [ 103 ] ;
52+ defaultMessages . maxlength = defaultMessages [ 201 ] ;
53+ defaultMessages . minlength = defaultMessages [ 200 ] ;
54+ defaultMessages . pattern = defaultMessages [ 202 ] ;
55+
4756 this . setDefaultMessages = function ( messages ) {
4857 defaultMessages = messages ;
4958 } ;
@@ -68,12 +77,14 @@ angular.module('schemaForm').provider('sfErrorMessage', function() {
6877 * @param {string } error the error code, i.e. tv4-xxx for tv4 errors, otherwise it's whats on
6978 * ngModel.$error for custom errors.
7079 * @param {Any } value the actual model value.
80+ * @param {Any } viewValue the viewValue
7181 * @param {Object } form a form definition object for this field
7282 * @param {Object } global the global validation messages object (even though its called global
7383 * its actually just shared in one instance of sf-schema)
7484 * @return {string } The error message.
7585 */
76- service . interpolate = function ( error , value , form , global ) {
86+ service . interpolate = function ( error , value , viewValue , form , global ) {
87+ console . log ( error , value , viewValue )
7788 global = global || { } ;
7889 var validationMessage = form . validationMessage || { } ;
7990
@@ -99,6 +110,7 @@ angular.module('schemaForm').provider('sfErrorMessage', function() {
99110 var context = {
100111 error : error ,
101112 value : value ,
113+ viewValue : viewValue ,
102114 form : form ,
103115 schema : form . schema ,
104116 title : form . title || ( form . schema && form . schema . title )
0 commit comments