JSFiddle - React, Tailwind, and code Playground

by Martin Sjåstad

JavaScript

<? php foreach($positions as $position) { ?> $('.search-sgroup-user-<?=$position?>').on('focus.autocomplete', function () {
            console.log('attaching focus.autocomplete event on ');
            console.dir($(this));
            $(this).autocomplete({
                focus: function (event, ui) {
                    $(this).val(ui.item.label);
                    $(this).attr('name', 'unit-' + ui.item.id);
                    return false;
                },
                minLength: 3,
                delay: 100,
                search: function (event, ui) {
                    ids = '';
                    count = $('#club-sgroups-<?=$position?> .sgroup-user-id').length;

                    exclude = new Array();
                    $('div.side_connection').each(function (i, v) {
                        if ($(v).attr('id')) {
                            exclude[exclude.length] = $(v).attr('id').replace("connection-", "");
                        }
                    });
                    ids = exclude.toString();

                    console.log(ids);

                    // update the url with academics before sending the request
                    $(this).autocomplete("option", "source", function (request, response) {
                        // if term is in cache return it
                        // !!!cache doesen't work, because I can't exclude already added admins!!!'
                        // TODO: have a look if there is a opportunity
                        // ajax call to get search resp
                        $.ajax({
                            url: '/json/search_users/',
                            type: 'POST',
                            data: {
                                'except_ids': ids,
                                    'term': request.term,
                                    'action': 'search'
                            },
                            success: function (data) {
                                //put...