Statistics
| Branch: | Tag: | Revision:

root / cloudcms / static / cloudcms / js / form-errors.js @ c1468bcc

History | View | Annotate | Download (1.4 kB)

1
(function($){
2

    
3
  $.fn.formErrors = function(options) {  
4
    return this.each(function() {
5
        var $this = $(this);
6

    
7
        // does the field has any errors ?
8
        var errors = $this.find(".errorlist");
9
        if (errors.length == 0) {
10
            return;
11
        }
12
        
13
        // create the custom error message block
14
        // and copy the contents of the original
15
        // error list
16
        var el = $('<div class="form-error" />');
17
        errors.find("li").each(function(){
18
            el.html(el.html() + $(this).text() + "<br />");
19
        })
20
        
21
        var formel = $this.find("input, select");
22
        var lbl = $this.find("label");
23
        var form = $this.closest("form");
24

    
25

    
26
        // append element on form row 
27
        // and apply the appropriate styles
28
        formel.closest(".form-row").append(el);
29
        errors.remove();
30
        var left = formel.width();
31
        var top = formel.height();
32
        var marginleft = lbl.width();
33
        
34
        // identify the position
35
        // forms with innerlbales class
36
        // display the label within the input fields
37
        if ($(form).hasClass("innerlabels")) {
38
            marginleft = 0;
39
        }
40
        
41
        var styles = {
42
            left: left + "px", 
43
            top: top + "px", 
44
            width: formel.outerWidth() - 10,
45
            marginLeft: marginleft,
46
            marginBottom: 5
47
        }
48
        el.css(styles);
49
    });
50

    
51
  };
52
})( jQuery );