File tree Expand file tree Collapse file tree 4 files changed +33
-5
lines changed
Expand file tree Collapse file tree 4 files changed +33
-5
lines changed Original file line number Diff line number Diff line change @@ -299,3 +299,23 @@ Intial Validation for the input false. You can make it to true!
299299<!-- set to true -->
300300<input type =" text" name =" firstName" ng-model =" firstName" validator =" required" initial-validity =" true" />
301301```
302+
303+ ### Custom Error/Success Message Function
304+ #### html
305+ Declare your valid and invalid callback functions. Make sure to pass the ` message ` param.
306+ ``` html
307+ <input type =" text" ng-model =" name" name =" inputName" validator =" required" valid-callback =" validationValidHandler(message)" invalid-callback =" validationInvalidHandler(message)" >
308+ ```
309+ #### Javascript
310+ Now you can call your own function and have access to the message.
311+ ``` javascript
312+ scope .validationValidHandler = function (message ){
313+ // you now have access to the error message
314+ displayMessage (message, ' success' );
315+ };
316+
317+ scope .validationInvalidHandler = function (message ){
318+ // you now have access to the error message
319+ displayMessage (message, ' error' );
320+ };
321+ ```
Original file line number Diff line number Diff line change 324324 messageElem . css ( 'display' , 'none' ) ;
325325 }
326326 ctrl . $setValidity ( ctrl . $name , true ) ;
327- if ( scope . validCallback ) scope . validCallback ( ) ;
327+ if ( scope . validCallback ) scope . validCallback ( {
328+ message : messageToShow
329+ } ) ;
328330 if ( $validationProvider . validCallback ) $validationProvider . validCallback ( element ) ;
329331
330332 return true ;
356358 messageElem . css ( 'display' , 'none' ) ;
357359 }
358360 ctrl . $setValidity ( ctrl . $name , false ) ;
359- if ( scope . inValidCallback ) scope . inValidCallback ( ) ;
361+ if ( scope . invalidCallback ) scope . invalidCallback ( {
362+ message : messageToShow
363+ } ) ;
360364 if ( $validationProvider . invalidCallback ) $validationProvider . invalidCallback ( element ) ;
361365
362366 return false ;
Original file line number Diff line number Diff line change 3232 messageElem . css ( 'display' , 'none' ) ;
3333 }
3434 ctrl . $setValidity ( ctrl . $name , true ) ;
35- if ( scope . validCallback ) scope . validCallback ( ) ;
35+ if ( scope . validCallback ) scope . validCallback ( {
36+ message : messageToShow
37+ } ) ;
3638 if ( $validationProvider . validCallback ) $validationProvider . validCallback ( element ) ;
3739
3840 return true ;
6466 messageElem . css ( 'display' , 'none' ) ;
6567 }
6668 ctrl . $setValidity ( ctrl . $name , false ) ;
67- if ( scope . inValidCallback ) scope . inValidCallback ( ) ;
69+ if ( scope . invalidCallback ) scope . invalidCallback ( {
70+ message : messageToShow
71+ } ) ;
6872 if ( $validationProvider . invalidCallback ) $validationProvider . invalidCallback ( element ) ;
6973
7074 return false ;
You can’t perform that action at this time.
0 commit comments