Referring back to your earlier comment, I don't think it's strictly correct to say that the autocomplete widget has an 'underlying' value (record key in your case) that persists and/or can be set. What happens is that when the user makes a selection, the widget passes you that value one time through the 'select' function that you supply. See the 'Custom data and display' example in the documentation for a good demonstration of this.
With that in mind, would the following steps have the desired result?
• Abstract out your select-person logic (i.e. what happens once a person is selected) into a separate function, called from the 'select' function in the .autocomplete() setup call.
• When the user creates a new related object, first set the 'label' (person's name in this case) into the input field with a simple .val() call.
• Then call the separate select-person function.
Here's some rough code (not checked) to demonstrate:
- $( '#auto' ).autocomplete({
- source: // whatever
- select: function( event, ui ) { ChosenPerson( ui.item.value ); }
- })
-
- function ChosenPerson( RecordKey ) {
- // Do the work required when a person (possibly a newly-created one) has been selected.
- }
-
- function NewPerson() {
- // Runs as part of creating a new person record. When done:
- ChosenPerson( RecordKey );
- }
Cheers,
Robert