autocomplete.tpl 1.47 KB
Newer Older
1
<select class="js-data-ajax" multiple="multiple" id="{{$id}}" name="{{$name}}[]" {{if $describedby}}aria-describedby="{{$describedby}}"{{/if}}>
Robert Lyon's avatar
Robert Lyon committed
2
3
4
5
6
7
{{if $initvalues}}
    {{foreach from=$initvalues item=value}}
    <option selected value="{{$value->id}}">{{$value->text}}</option>
    {{/foreach}}
{{/if}}
</select>
Naomi Guyer's avatar
Naomi Guyer committed
8

9
<script type="application/javascript">
10
11
12
{{if !$inblockconfig}}
    addLoadEvent(function () {
{{/if}}
Naomi Guyer's avatar
Naomi Guyer committed
13
14
15
16
    jQuery("#{{$id}}").select2({
        ajax: {
            url: "{{$ajaxurl}}",
            dataType: 'json',
Robert Lyon's avatar
Robert Lyon committed
17
18
19
            type: 'POST',
            delay: 250,
            data: function(params) {
Naomi Guyer's avatar
Naomi Guyer committed
20
                return {
Robert Lyon's avatar
Robert Lyon committed
21
22
23
24
25
                    'q': params.term,
                    'page': params.page || 0,
                    'sesskey': "{{$sesskey}}",
                    'offset': 0,
                    'limit': 10,
Naomi Guyer's avatar
Naomi Guyer committed
26
27
                }
            },
Robert Lyon's avatar
Robert Lyon committed
28
            processResults: function(data, page) {
Naomi Guyer's avatar
Naomi Guyer committed
29
30
                return {
                    results: data.results,
Robert Lyon's avatar
Robert Lyon committed
31
32
33
                    pagination: {
                        more: data.more
                    }
Naomi Guyer's avatar
Naomi Guyer committed
34
35
36
                };
            }
        },
37
        language: "{{$language}}",
Robert Lyon's avatar
Robert Lyon committed
38
39
40
41
42
        multiple: {{$multiple}},
        width: "{{$width}}",
        allowClear: {{$allowclear}},
        {{if $hint}}placeholder: "{{$hint}}",{{/if}}
        minimumInputLength: {{$mininputlength}},
Naomi Guyer's avatar
Naomi Guyer committed
43
44
        {{$extraparams|safe}}
    });
45
46
47
{{if !$inblockconfig}}
    });
{{/if}}
Naomi Guyer's avatar
Naomi Guyer committed
48
49
jQuery("#{{$id}}").prop('disabled', {{$disabled}});
</script>