-
Notifications
You must be signed in to change notification settings - Fork 36
/
form.js
65 lines (58 loc) · 1.46 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
(function($) {
var FormHelper = $.FormHelper = {};
/**
* Focus on the first available text field, used in admin to make the
* overall usability a bit better.
*
* @access public
* @return void
**/
FormHelper.foucusOnFirst = function(){
$("input:text:visible:first").focus();
}
/**
* generate a form input
*/
FormHelper.input = function(data, metaData) {
$('#' + metaData.target).empty();
if ($.Core.type(data) == 'string') {
}
$.FormHelper.select(data, metaData);
};
/**
* generate a select dropdown
*/
FormHelper.select = function(data, metaData) {
var options = '';
$.each(data, function(index, name) {
if(($.Core.type(name) == 'plainObject') || ($.Core.type(name) == 'array')) {
options += '<optgroup label="' + index + '">';
$.each(name, function(sub_index, sub_name) {
options += '<option value="' + sub_index + '">' + sub_name + '</option>';
});
options += '</optgroup>';
}
else {
options += '<option value="' + index + '">' + name + '</option>';
}
});
$('#' + metaData.target).empty().html(options);
};
/**
* toggle checkboxes
*/
FormHelper.checkboxToggleAll = function() {
var tog = false;
var toggleId = '#' + Infinitas.model + 'All';
$(toggleId).click(function(){
$("input:checkbox[not:"+toggleId+"]").attr("checked",!tog).change();
tog = !tog;
});
};
/**
* image dropdown
*/
FormHelper.imageDropdown = function(fieldId) {
$("#" + fieldId).msDropDown();
};
})(jQuery);