Passed
Push — master ( e1d21b...121756 )
by Anthony
02:12
created

assets/js/form_blocks/inputs.js   A

Complexity

Total Complexity 23
Complexity/F 2.88

Size

Lines of Code 80
Function Count 8

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 0
nc 32
dl 0
loc 80
rs 10
c 1
b 0
f 1
wmc 23
mnd 3
bc 18
fnc 8
bpm 2.25
cpm 2.875
noi 6
1
$(document).ready(function() {
2
	function ValidateDate(dtValue)  {
3
		var dtRegex = new RegExp(/\b\d{1,2}[\/-]\d{1,2}[\/-]\d{4}\b/);
4
		return dtRegex.test(dtValue);
5
	}
6
7
	//---------------------------- EFFECT MATERIAL ON INPUT INPUT -----------------------------//
8
	$('.block input').focus(function() {
9
		$parent = $(this).parent();
0 ignored issues
show
Bug introduced by
The variable $parent seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.$parent.
Loading history...
10
		$parent.addClass('is-focused has-label');
11
		$parent.removeClass('invalid');
12
	});
13
14
	$('.block input').blur(function() {
15
		$parent = $(this).parent();
0 ignored issues
show
Bug introduced by
The variable $parent seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.$parent.
Loading history...
16
		$this = $(this);
0 ignored issues
show
Bug introduced by
The variable $this seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.$this.
Loading history...
17
18
        var type = $this.attr("type-val");
19
        var min = $this.attr("min");
20
        var max = $this.attr("max");
21
22
        if (type == "string") {
23
            if ($this.val() == "") {
24
                $parent.addClass('invalid');
25
                $parent.removeClass('has-label');
26
            }
27
            else if (($this.val().length < min) || ($this.val().length > max)) {
28
                $parent.addClass('invalid');
29
            }
30
        }
31
        else if (type == "date") {
32
            if (($this.attr('name') == "date") && (!ValidateDate($this.val()))) {
33
                $parent.addClass('invalid');
34
            }
35
        }
36
37
		$parent.removeClass('is-focused');
38
	});
39
40
	$('.block input').each(function() {
41
		if (($(this).val() != '') || ($(this).val() != 0)) {
42
			$(this).parent().addClass('has-label');
43
		}
44
	});
45
46
47
	$('.block textarea').focus(function() {
48
		$parent = $(this).parent();
0 ignored issues
show
Bug introduced by
The variable $parent seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.$parent.
Loading history...
49
		$parent.addClass('is-focused has-label');
50
		$parent.removeClass('invalid');
51
	});
52
53
	$('.block textarea').blur(function() {
54
		$parent = $(this).parent();
0 ignored issues
show
Bug introduced by
The variable $parent seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.$parent.
Loading history...
55
		$this = $(this);
0 ignored issues
show
Bug introduced by
The variable $this seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.$this.
Loading history...
56
57
        var type = $this.attr("type-val");
58
        var min = $this.attr("min");
59
        var max = $this.attr("max");
60
61
        if (type == "string") {
62
            if ($this.val() == "") {
63
                $parent.addClass('invalid');
64
                $parent.removeClass('has-label');
65
            }
66
            else if (($this.val().length < min) || ($this.val().length > max)) {
67
                $parent.addClass('invalid');
68
            }
69
        }
70
71
		$parent.removeClass('is-focused');
72
	});
73
74
	$('.block textarea').each(function() {
75
		if (($(this).val() != '') || ($(this).val() != 0)) {
76
			$(this).parent().addClass('has-label');
77
		}
78
	});
79
    //---------------------------- END EFFECT MATERIAL ON INPUT INPUT -----------------------------//
80
})