aboutsummaryrefslogtreecommitdiffstats
path: root/moon_gui/static/app/services/gui/form.service.js
blob: e436593c2c636228e081f338fdf3607f144c13a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
 * @author arnaud marhin<arnaud.marhin@orange.com>
 */

(function() {

	'use strict';
	
	angular
		.module('moon')
				.factory('formService', formService);
		
	function formService() {

        var service = {};

        service.isInvalid = isInvalid;
        service.checkFieldsValidity = checkFieldsValidity;

        return service;
		
		function isInvalid(form) {
			return form.$invalid;
		}
		
		function checkFieldsValidity(form) {
			
			var validationErrorKeys = _.keys(form.$error);
        	
    		_(validationErrorKeys).each(function(anErrorKey) {
    			
    			var formFields = _.values(form.$error[anErrorKey]);
    			
    			_(formFields).each(function(aFormField) {
    				
    				aFormField.$dirty = true;
    				aFormField.$setValidity(anErrorKey, false);
    				
    			});
    			
    		});
			
		}

	}

})();