-
Notifications
You must be signed in to change notification settings - Fork 1
/
form.js
83 lines (74 loc) · 2.74 KB
/
form.js
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
$(document).ready(function() {
$('form').submit(function() {
var postData = $(this).serialize();
$.post($(this).attr('action'), postData, null, "script");
return false;
});
$("a.display_form").live("click",function(event) {
var link = $(this);
var id_attribute_name = link.attr('id').split('_');
var title_array = link.text().split(' ');
$('form').toggle(function() {
if('view' == link.text().substr(0,4)) {
link.text('hide ' + title_array[1]);
} else {
link.text('view ' + title_array[1]);
}
});
});
// Disable autocomplete for our imput elements
$('input').attr('autocomplete','off');
// Customised validations for all of our forms
$.fn.customValidations = function(options) {
var opts = $.extend({}, $.fn.animateIconPanel.defaults, options);
$(this).validate({
ignoreTitle: true,
focusInvalid: true,
clearFocus: true,
successClass: 'valid',
errorClass: 'error ui-state-error',
errorElement: "span",
highlight: function(element, errorClass, validClass) {
$(element).fadeOut(function() {
var $parent = $(element).parent();
var $validElements = $parent.find('span.valid');
$validElements.remove();
$(element).addClass(errorClass).removeClass(validClass);
$parent.addClass(errorClass).removeClass(validClass);
$(element).show();
});
},
unhighlight: function(element, errorClass, validClass) {
var $parent = $(element).parent();
var $invalidElements = $parent.find('span.error');
$invalidElements.html('');
$(element).removeClass(errorClass).addClass(validClass);
$invalidElements.removeClass(errorClass).addClass(validClass);
$parent.removeClass(errorClass).addClass(validClass);
},
success: function(label) {
var $parent = $(label).parent();
var $validElements = $parent.find('span.valid');
$validElements.remove();
label.removeClass('error ui-state-error').addClass("valid");
},
errorPlacement: function(error, element) {
var $warningSpan = $('<span></span')
.css({'float': 'left', 'margin': '0.3em', 'padding-left': '5px'})
.addClass('ui-icon invalid'),
$parent = element.parent(),
$previousError = $parent.find('span.error');
if ($previousError.html() == null) {
error
.wrap("<span class='ui-state-error ui-corner-all'></span>")
.insertAfter(element)
.prepend($warningSpan);
} else {
$previousError.show();
}
},
rules: opts.rules
});
}
$('fieldset.inputs > ol li').generateFormatasticTooltips();
});