Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide docs and examples #3

Open
wernerkrauss opened this issue Mar 13, 2015 · 1 comment
Open

Provide docs and examples #3

wernerkrauss opened this issue Mar 13, 2015 · 1 comment

Comments

@wernerkrauss
Copy link

This seems like a very useful formfield, could you please provide some more informations on how to set it up correctly?

@dhensby
Copy link
Member

dhensby commented Mar 13, 2015

Yes, we need to do docs

Some examples of how we used it for now:

AutocompleteField::create(
    'MemberID',
    'Email address',
    array($this, 'getMembers'),
    array(
        'searchKey' => 'NiceTitle',
        'displayKey' => 'NiceTitle',
        'rawFieldKey' => 'Email',
        'rawValueFieldClass' => 'EmailField',
    )
)->setRecordFormatter('MemberExtension::frontend_autocomplete');
static public function frontend_autocomplete($data) {
    $data = $data->toArray();
    foreach($data as &$member) {
        $niceTitle = $member->getName() ?: 'Invited member';
        $niceTitle = call_user_func_array(
            'sprintf',
            array(
                '%s • %s',
                $niceTitle,
                $member->Email,
            )
        );
        $member = array(
            'ID' => $member->ID,
            'Email' => $member->Email ?: $member->getName(),
            'SafeName' => $member->getSafeName(),
            'NiceTitle' => $niceTitle,
        );
    }
    return $data;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants