Thank you Nithya.
I wish that (stackoverflow.com/.../crm-2016-autocomplete - "You must have a lookup control on the form in order for the autocomplete to render.") were the solution but it's not. I do have a lookup on the form and still have the problem. Only way I've found to solve the problem is to not use auto-complete on quick forms.
Code and errors below for reference if anyone has ideas. Code works as expected on full forms.
TypeError: Cannot read property 'addOnKeyPress' of null
at suggestStates (https://crm.***/%7B636203259450000749%7D/WebResources/new_Address_Phone_main_libraryjs?ver=1238576589:238:52)
at eval (eval at RunHandlerInternal (https://crm.***/form/ClientApiWrapper.aspx?ver=1238576589:153:1), <anonymous>:1:1)
at RunHandlerInternal (https://crm.***/form/ClientApiWrapper.aspx?ver=1238576589:158:1)
at RunHandlers (https://crm.***/form/ClientApiWrapper.aspx?ver=1238576589:117:1)
at OnScriptTagLoaded (https://crm.***/form/ClientApiWrapper.aspx?ver=1238576589:232:1)
at https://crm.***/form/ClientApiWrapper.aspx?ver=1238576589:201:1


function suggestStates() {
// List of states to suggest
// Good explanation: blog.singular.co.za/.../auto-completion-for-text-controls-on-crm-2016-forms
States = [
{ name: 'AL', spell: 'Alabama', code: 'S01' },
{ name: 'AK', spell: 'Alaska', code: 'S02' },
{ name: 'AZ', spell: 'Arizona', code: 'S03' },
{ name: 'AR', spell: 'Arkansas', code: 'S04' },
{ name: 'CA', spell: 'California', code: 'S05' },
{ name: 'CO', spell: 'Colorado', code: 'S06' },
{ name: 'CT', spell: 'Connecticut', code: 'S07' },
{ name: 'DE', spell: 'Delaware', code: 'S08' },
{ name: 'FL', spell: 'Florida', code: 'S09' },
{ name: 'GA', spell: 'Georgia', code: 'S10' },
{ name: 'HI', spell: 'Hawaii', code: 'S11' },
{ name: 'ID', spell: 'Idaho', code: 'S12' },
{ name: 'IL', spell: 'Illinois', code: 'S13' },
{ name: 'IN', spell: 'Indiana', code: 'S14' },
{ name: 'IA', spell: 'Iowa', code: 'S15' },
{ name: 'KS', spell: 'Kansas', code: 'S16' },
{ name: 'KY', spell: 'Kentucky', code: 'S17' },
{ name: 'LA', spell: 'Louisiana', code: 'S18' },
{ name: 'ME', spell: 'Maine', code: 'S19' },
{ name: 'MD', spell: 'Maryland', code: 'S20' },
{ name: 'MA', spell: 'Massachusetts', code: 'S21' },
{ name: 'MI', spell: 'Michigan', code: 'S22' },
{ name: 'MN', spell: 'Minnesota', code: 'S23' },
{ name: 'MS', spell: 'Mississippi', code: 'S24' },
{ name: 'MO', spell: 'Missouri', code: 'S25' },
{ name: 'MT', spell: 'Montana', code: 'S26' },
{ name: 'NE', spell: 'Nebraska', code: 'S27' },
{ name: 'NV', spell: 'Nevada', code: 'S28' },
{ name: 'NH', spell: 'New Ampshire', code: 'S29' },
{ name: 'NJ', spell: 'New Jersey', code: 'S30' },
{ name: 'NM', spell: 'New Mexico', code: 'S31' },
{ name: 'NY', spell: 'New York', code: 'S32' },
{ name: 'NC', spell: 'North Carolina', code: 'S33' },
{ name: 'ND', spell: 'North Dakota', code: 'S34' },
{ name: 'OH', spell: 'Ohio', code: 'S35' },
{ name: 'OK', spell: 'Oklahoma', code: 'S36' },
{ name: 'OR', spell: 'Oregon', code: 'S37' },
{ name: 'PA', spell: 'Pennsylvania', code: 'S38' },
{ name: 'RI', spell: 'Rhode Island', code: 'S39' },
{ name: 'SC', spell: 'South Carolina', code: 'S40' },
{ name: 'SD', spell: 'South Dakota', code: 'S41' },
{ name: 'TN', spell: 'Tennessee', code: 'S42' },
{ name: 'TX', spell: 'Texas', code: 'S43' },
{ name: 'UT', spell: 'Utah', code: 'S44' },
{ name: 'VT', spell: 'Vermont', code: 'S45' },
{ name: 'VA', spell: 'Virginia', code: 'S46' },
{ name: 'WA', spell: 'Washington', code: 'S47' },
{ name: 'WV', spell: 'West Virginia', code: 'S48' },
{ name: 'WI', spell: 'Wisconsin', code: 'S49' },
{ name: 'WY', spell: 'Wyoming', code: 'S50' }
];
var keyPressFcn = function (ext) {
// Get value typed by user
try {
var userInput = Xrm.Page.getControl("address1_stateorprovince").getValue();
// Define an empty resultset that will be used as the source for the autocomplete box.
resultSet = {
results: new Array(),
commands: {
id: "sp_commands",
// This will put an icon bottom right of window
//icon: "../WebResources/new_City_16.png",
//This will add the Link at the bottom of the auto complete search result
label: "",
action: function () {
// Specify what you want to do when the user clicks the "Learn More" link at the bottom of the auto-completion list.
// For this sample, we are just opening a page that provides information on working with accounts in CRM.
// window.open("www.microsoft.com/.../create-or-edit-an-account.aspx");
}
}
};
// In this example, we will cycle through the array of possible values looking for a match.
var userInputLowerCase = userInput.toLowerCase();
for (i = 0; i < States.length; i++) {
// Check if the entry in the array matches the typed characters.
// If so, add the matching values to the resultset that will be displayed in the autocomplete box.
if (userInputLowerCase === States[i].name.substring(0, userInputLowerCase.length).toLowerCase()) {
resultSet.results.push({
id: i,
fields: [States[i].name, States[i].spell]
});
}
// Limit the autocomplete list to 10 entries
if (resultSet.results.length >= 10) break;
}
// Display the autocomplete box if there were matching entries found. Otherwise, hide it.
if (resultSet.results.length > 0) {
ext.getEventSource().showAutoComplete(resultSet);
} else {
ext.getEventSource().hideAutoComplete();
}
} catch (e) {
// Handle any exceptions. In the sample code, we are just displaying the exception, if any.
console.log(e);
}
};
var keyPressFcn2 = function (ext) {
try {
var userInput = Xrm.Page.getControl("address2_stateorprovince").getValue();
resultSet = {
results: new Array(),
commands: {
id: "sp_commands",
label: "",
action: function () {}
}
};
var userInputLowerCase = userInput.toLowerCase();
for (i = 0; i < States.length; i++) {
if (userInputLowerCase === States[i].name.substring(0, userInputLowerCase.length).toLowerCase()) {
resultSet.results.push({
id: i,
fields: [States[i].name, States[i].spell]
});
}
if (resultSet.results.length >= 10) break;
}
if (resultSet.results.length > 0) {
ext.getEventSource().showAutoComplete(resultSet);
} else {
ext.getEventSource().hideAutoComplete();
}
} catch (e) {
console.log(e);
}
};
var keyPressFcn3 = function (ext) {
try {
var userInput = Xrm.Page.getControl("address1_composite_compositionLinkControl_address1_stateorprovince").getValue();
resultSet = {
results: new Array(),
commands: {
id: "sp_commands",
label: "",
action: function () { }
}
};
var userInputLowerCase = userInput.toLowerCase();
for (i = 0; i < States.length; i++) {
if (userInputLowerCase === States[i].name.substring(0, userInputLowerCase.length).toLowerCase()) {
resultSet.results.push({
id: i,
fields: [States[i].name, States[i].spell]
});
}
if (resultSet.results.length >= 10) break;
}
if (resultSet.results.length > 0) {
ext.getEventSource().showAutoComplete(resultSet);
} else {
ext.getEventSource().hideAutoComplete();
}
} catch (e) {
console.log(e);
}
};
Xrm.Page.getControl("address1_stateorprovince").addOnKeyPress(keyPressFcn);
Xrm.Page.getControl("address2_stateorprovince").addOnKeyPress(keyPressFcn2);
Xrm.Page.getControl("address1_composite_compositionLinkControl_address1_stateorprovince").addOnKeyPress(keyPressFcn3);
}