Statistics
| Branch: | Tag: | Revision:

root / astakos / im / static / im / js / forms.js @ 86243acc

History | View | Annotate | Download (1.9 kB)

1
(function($){
2
  
3
  $.fn.formCheckBoxes = function(options) {
4
    
5
    return this.each(function() {
6
      var $this = $(this);
7
      var el = $('<span class="checkbox-widget" />');
8
    
9
      $this.hide();
10
      
11
      if ($this.is("checked")) {
12
        el.addClass("checked");  
13
      }
14

    
15
      el.click(function() {
16
        el.toggleClass("checked");
17
        $this.attr('checked', el.hasClass("checked"));
18
      })
19

    
20
      $this.after(el);
21
    });
22

    
23

    
24
  }
25

    
26
  $.fn.formErrors = function(options) {  
27
    return this.each(function() {
28
        var $this = $(this);
29

    
30
        // does the field has any errors ?
31
        var errors = $this.find(".errorlist");
32
        if (errors.length == 0) {
33
            return;
34
        }
35
        
36
        // create the custom error message block
37
        // and copy the contents of the original
38
        // error list
39
        var el = $('<div class="form-error" />');
40
        errors.find("li").each(function(){
41
            el.html(el.html() + $(this).text() + "<br />");
42
        })
43
        
44
        var formel = $this.find("input, select");
45
        var lbl = $this.find("label");
46
        var form = $this.closest("form");
47

    
48

    
49
        // append element on form row 
50
        // and apply the appropriate styles
51
        formel.closest(".form-row").append(el);
52
        errors.remove();
53
        var left = formel.width();
54
        var top = formel.height();
55
        var marginleft = lbl.width();
56
        
57
        // identify the position
58
        // forms with innerlbales class
59
        // display the label within the input fields
60
        if ($(form).hasClass("innerlabels")) {
61
            marginleft = 0;
62
        }
63
        
64
        var styles = {
65
            left: left + "px", 
66
            top: top + "px", 
67
            width: formel.outerWidth() - 10,
68
            marginLeft: marginleft,
69
            marginBottom: 5
70
        }
71
        el.css(styles);
72
    });
73

    
74
  };
75
})( jQuery );