@@ -8,6 +8,19 @@ describe('directive', function() {
88 } )
99 ) ;
1010
11+ tv4 . defineError ( 'EMAIL' , 10001 , 'Invalid email address' ) ;
12+ tv4 . defineKeyword ( 'email' , function ( data , value , schema ) {
13+ if ( schema . email ) {
14+ if ( / ^ \S + @ \S + $ / . test ( data ) ) {
15+ return null ;
16+ }
17+ return {
18+ code : 10001
19+ } ;
20+ }
21+ return null ;
22+ } ) ;
23+
1124 exampleSchema = {
1225 "type" : "object" ,
1326 "title" : "Person" ,
@@ -71,19 +84,6 @@ describe('directive', function() {
7184 ) ;
7285
7386 inject ( function ( $compile , $rootScope ) {
74- tv4 . defineError ( 'EMAIL' , 10001 , 'Invalid email address' ) ;
75- tv4 . defineKeyword ( 'email' , function ( data , value , schema ) {
76- if ( schema . email ) {
77- if ( / ^ \S + @ \S + $ / . test ( data ) ) {
78- return null ;
79- }
80- return {
81- code : 10001
82- } ;
83- }
84- return null ;
85- } ) ;
86-
8787 var scope = $rootScope . $new ( ) ;
8888 scope . obj = { "email" : "NULL" } ;
8989
@@ -111,4 +111,48 @@ describe('directive', function() {
111111 form . $valid . should . be . false ;
112112 } ) ;
113113 } ) ;
114+
115+ it ( 'should allow custom tv4 error default message to be set' , function ( ) {
116+ //TODO test message rename
117+ // app.config(['sfErrorMessageProvider', function(sfErrorMessageProvider) {
118+ // sfErrorMessageProvider.setDefaultMessage(10001, 'Whoa! Can you double check that email address for me?');
119+ // }]);
120+
121+ tmpl = angular . element (
122+ '<div>' +
123+ '<form name="testform" sf-schema="schema" sf-form="form" sf-model="obj"></form>' +
124+ '{{obj}}' +
125+ '</div>'
126+ ) ;
127+
128+ inject ( function ( $compile , $rootScope ) {
129+
130+ var scope = $rootScope . $new ( ) ;
131+ scope . obj = { "email" : "NULL" } ;
132+
133+ scope . schema = exampleSchema ;
134+
135+ scope . form = [
136+ {
137+ "key" : "email" ,
138+ "placeholder" : "Enter contact email" ,
139+ "feedback" : false
140+ } ,
141+ {
142+ "type" : "submit" ,
143+ "style" : "btn-info" ,
144+ "title" : "OK"
145+ }
146+ ] ;
147+
148+ $compile ( tmpl ) ( scope ) ;
149+ $rootScope . $apply ( ) ;
150+
151+ var form = tmpl . find ( 'form' ) . eq ( 0 ) . controller ( 'form' ) ;
152+
153+ form . $valid . should . be . true ;
154+ tmpl . find ( 'input.btn-info' ) . click ( ) ;
155+ //TODO form.$valid.should.be.false;
156+ } ) ;
157+ } ) ;
114158} ) ;
0 commit comments