         @render()
 
 
-    onNewGuest: ->
-        email = @$('input[name="guest-name"]').val()
+    # Handle guest addition. `userInfo` is passed when called by the typeahead.
+    onNewGuest: (userInfo = null) ->
+
+        if userInfo?
+            [email, contactID] = userInfo.split(';')
+        else
+            email = @$('input[name="guest-name"]').val()
+            contactID = null
+
         guests = @model.get('attendees') or []
         if not _.findWhere(guests, email: email)
             # Clone the source array, otherwise it's not considered as

        "click .add-new-guest": "onNewGuest"
        "click .guest-delete": "onRemoveGuest"
        'keyup input[name="guest-name"]': "onKeyup"


    getRenderData: ->

            $guests.append row


        @configureGuestTypeahead()


    # Configure the auto-complete on contacts.
    configureGuestTypeahead: ->
        # If it's already configured, no need to do it again.
        unless @_configured
            @_configured = true
            @$('input[name="guest-name"]').typeahead
                source: app.contacts.asTypeaheadSource()
                matcher: (contact) ->
                    old = $.fn.typeahead.Constructor::matcher
                    return old.call this, contact.display
                sorter: (contacts) ->
                    beginswith = []
                    caseSensitive = []
                    caseInsensitive = []

                    while (contact = contacts.shift())
                        item = contact.display
                        if not item.toLowerCase().indexOf(this.query.toLowerCase())
                            beginswith.push contact
                        else if ~item.indexOf this.query
                            caseSensitive.push contact
                        else caseInsensitive.push contact

                    return beginswith.concat caseSensitive, caseInsensitive

                highlighter: (contact) ->
                    old = $.fn.typeahead.Constructor::highlighter
                    return old.call this, contact.display

                updater: @onNewGuest.bind(@)


    onRemoveGuest: (event) ->
        # Get which guest to remove.
        index = @$(event.target).parents('li').attr 'data-index'
