Bug 31646: Add Select2 focus to text search field
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / restrictiontypes.js
1 jQuery.validator.addMethod( "restrictionCode", function(value){
2     var ex = Object.keys(existing);
3     return (value.length > 0 && ex.indexOf(value.toUpperCase()) > -1) ?
4         false :
5         true;
6 }, MSG_DUPLICATE_CODE);
7
8 jQuery.validator.addMethod( "restrictionDisplayText", function(value){
9     var ex = Object.values(existing).map(function(el) {
10         return el.toLowerCase();
11     });
12     return (value.length > 0 && ex.indexOf(value.toLowerCase()) > -1) ?
13         false :
14         true;
15 }, MSG_DUPLICATE_DISPLAY_TEXT);
16
17 $(document).ready(function() {
18     KohaTable("restriction_types", {
19         "aoColumnDefs": [{
20             "aTargets": [-1],
21             "bSortable": false,
22             "bSearchable": false
23         }, {
24             "aTargets": [0, 1],
25             "sType": "natural"
26         }, ],
27         "aaSorting": [
28             [1, "asc"]
29         ],
30         "sPaginationType": "full",
31         "exportColumns": [0,1],
32     });
33
34     $("#restriction_form").validate({
35         rules: {
36             code: {
37                 required: true,
38                 restrictionCode: true
39             },
40             display_text: {
41                 required: true,
42                 restrictionDisplayText: true
43             }
44         },
45         messages: {
46             code: {
47                 restrictionCode: MSG_DUPLICATE_CODE
48             },
49             display_text: {
50                 restrictionDisplayText: MSG_DUPLICATE_DISPLAY_TEXT
51             }
52         }
53     });
54 });