concrete/src/Form/Service/Widget/UserSelector.php
public function quickSelect($fieldName, $uID = false, $miscFields = [])
    {
        $v = View::getRequestInstance();
        $v->requireAsset('selectize');

        $request = $this->app->make(Request::class);
        if ($request->request->has($fieldName)) {
            $selectedUID = $request->request->get($fieldName);
        } elseif ($request->query->has($fieldName)) {
            $selectedUID = $request->query->get($fieldName);
        } else {
            $selectedUID = $uID;
        }
        if ($selectedUID && $this->app->make(Numbers::class)->integer($selectedUID, 1)) {
            $userInfo = $this->app->make(UserInfoRepository::class)->getByID((int) $selectedUID);
        } else {
            $userInfo = null;
        }
        $selectedUID = $userInfo ? $userInfo->getUserID() : null;

        $valt = $this->app->make('token');
        $token = $valt->generate('quick_user_select_' . $fieldName);

        $identifier = $this->app->make(Identifier::class)->getString(32);

        $selectizeOptions = [
            'valueField' => 'value',
            'labelField' => 'label',
            'searchField' => ['label'],
            'maxItems' => 1,
        ];
        if ($userInfo) {
            $selectizeOptions += [
                'options' => [
                    [
                        'label' => h($userInfo->getUserDisplayName()),
                        'value' => $selectedUID,
                    ],
                ],
                'items' => [
                    $selectedUID,
                ],
            ];
        }
        $selectizeOptions = json_encode($selectizeOptions);
        $input = $this->app->make('helper/form')->hidden($fieldName, '', $miscFields);
        $ajaxUrlBase = json_encode(REL_DIR_FILES_TOOLS_REQUIRED . '/users/autocomplete?key=' . rawurlencode($fieldName) . '&token=' . rawurldecode($token));

        return <<<EOT
<span id="ccm-quick-user-selector-{$identifier}" class="ccm-quick-user-selector">{$input}</span>
<script>
$(function () {
    var options = {$selectizeOptions};
    options.load = function(query, callback) {
        if (!query.length) {
            return callback();
        }
        $.ajax({
            url: {$ajaxUrlBase} + '&term=' + encodeURIComponent(query),
            type: 'GET',
			dataType: 'json',
            error: function() {
                callback();
            },
            success: function(res) {
                callback(res);
            }
        });
    };
    $('#ccm-quick-user-selector-{$identifier} input')
        .unbind()
        .selectize(options)
    ;
});
</script>
EOT
        ;
    }
public function quickSelect($fieldName, $uID = false, $miscFields = [])
    {
        $v = View::getRequestInstance();
        $v->requireAsset('selectize');

        $request = $this->app->make(Request::class);
        if ($request->request->has($fieldName)) {
            $selectedUID = $request->request->get($fieldName);
        } elseif ($request->query->has($fieldName)) {
            $selectedUID = $request->query->get($fieldName);
        } else {
            $selectedUID = $uID;
        }
        if ($selectedUID && $this->app->make(Numbers::class)->integer($selectedUID, 1)) {
            $userInfo = $this->app->make(UserInfoRepository::class)->getByID((int) $selectedUID);
        } else {
            $userInfo = null;
        }
        $selectedUID = $userInfo ? $userInfo->getUserID() : null;

        $valt = $this->app->make('token');
        $token = $valt->generate('quick_user_select_' . $fieldName);

        $identifier = $this->app->make(Identifier::class)->getString(32);

        $selectizeOptions = [
            'valueField' => 'value',
            'labelField' => 'label',
            'searchField' => ['label'],
            'maxItems' => 1,
        ];
        if ($userInfo) {
            $selectizeOptions += [
                'options' => [
                    [
                        'label' => h($userInfo->getUserDisplayName()),
                        'value' => $selectedUID,
                    ],
                ],
                'items' => [
                    $selectedUID,
                ],
            ];
        }
        $selectizeOptions = json_encode($selectizeOptions);
        $input = $this->app->make('helper/form')->hidden($fieldName, '', $miscFields);
        $ajaxUrlBase = json_encode(REL_DIR_FILES_TOOLS_REQUIRED . '/users/autocomplete?key=' . rawurlencode($fieldName) . '&token=' . rawurldecode($token));

        return <<<EOT
<span id="ccm-quick-user-selector-{$identifier}" class="ccm-quick-user-selector">{$input}</span>
<script>
$(function () {
    var options = {$selectizeOptions};
    options.load = function(query, callback) {
        if (!query.length) {
            return callback();
        }
        $.ajax({
            url: {$ajaxUrlBase} + '&term=' + encodeURIComponent(query),
            type: 'GET',
			dataType: 'json',
            error: function() {
                callback();
            },
            success: function(res) {
                callback(res);
            }
        });
    };
    $('#ccm-quick-user-selector-{$identifier} input')
        .unbind()
        .selectize(options)
    ;
});
</script>
EOT
        ;
    }
public function quickSelect ( $ fieldName , $ uID = false , $ miscFields = [ ] ) { $ v = View :: getRequestInstance ( ) ; $ v -> requireAsset ( 'selectize' ) ; $ request = $ this -> app -> make ( Request :: class ) ; if ( $ request -> request -> has ( $ fieldName ) ) { $ selectedUID = $ request -> request -> get ( $ fieldName ) ; } elseif ( $ request -> query -> has ( $ fieldName ) ) { $ selectedUID = $ request -> query -> get ( $ fieldName ) ; } else { $ selectedUID = $ uID ; } if ( $ selectedUID && $ this -> app -> make ( Numbers :: class ) -> integer ( $ selectedUID , 1 ) ) { $ userInfo = $ this -> app -> make ( UserInfoRepository :: class ) -> getByID ( ( int ) $ selectedUID ) ; } else { $ userInfo = null ; } $ selectedUID = $ userInfo ? $ userInfo -> getUserID ( ) : null ; $ valt = $ this -> app -> make ( 'token' ) ; $ token = $ valt -> generate ( 'quick_user_select_' . $ fieldName ) ; $ identifier = $ this -> app -> make ( Identifier :: class ) -> getString ( 32 ) ; $ selectizeOptions = [ 'valueField' => 'value' , 'labelField' => 'label' , 'searchField' => [ 'label' ] , 'maxItems' => 1 , ] ; if ( $ userInfo ) { $ selectizeOptions += [ 'options' => [ [ 'label' => h ( $ userInfo -> getUserDisplayName ( ) ) , 'value' => $ selectedUID , ] , ] , 'items' => [ $ selectedUID , ] , ] ; } $ selectizeOptions = json_encode ( $ selectizeOptions ) ; $ input = $ this -> app -> make ( 'helper/form' ) -> hidden ( $ fieldName , '' , $ miscFields ) ; $ ajaxUrlBase = json_encode ( REL_DIR_FILES_TOOLS_REQUIRED . '/users/autocomplete?key=' . rawurlencode ( $ fieldName ) . '&token=' . rawurldecode ( $ token ) ) ; return  <<<EOT
<span id="ccm-quick-user-selector-{$identifier}" class="ccm-quick-user-selector">{$input}</span>
<script>
$(function () {
    var options = {$selectizeOptions};
    options.load = function(query, callback) {
        if (!query.length) {
            return callback();
        }
        $.ajax({
            url: {$ajaxUrlBase} + '&term=' + encodeURIComponent(query),
            type: 'GET',
			dataType: 'json',
            error: function() {
                callback();
            },
            success: function(res) {
                callback(res);
            }
        });
    };
    $('#ccm-quick-user-selector-{$identifier} input')
        .unbind()
        .selectize(options)
    ;
});
</script>
EOT ; }
Build the HTML to be placed in a page to choose a user using a select with users pupulated dynamically with ajax requests.

@param string $fieldName the name of the field
@param int|false $uID the ID of the user to be initially selected
@param array $miscFields additional fields appended to the hidden input element (a hash array of attributes name => value), possibly including 'class'

@return string

@example
<code>
$userSelector->quickSelect('userID', USER_SUPER_ID); // prints out the admin user and makes it changeable.
</code>.
Build the HTML to be placed in a page to choose a user using a select with users pupulated dynamically with ajax requests .