Set Combo value not in list when loading form from connector

I have a form with a combo box on it, in which I allow users to select from the list or to type in their own value. It works fine to save a typed-in value; I can see it in the database. However, when I load the data back into the form via FormConnector, if the value for the combo isn’t in the list, the combo is left blank. If the user doesn’t notice it and saves the form again, the value is set to a blank value in the database.

Is there a way to load the combo value from the database without it being in the list?

I was able to solve my own issue, although this may be something to look at for future development.

By logging the form object after the data load, I saw the _last_load_data object within it. I was able to set the combo value with the following line in the callback of my form load (Should also work in an “onXLE” event function):

myForm.getCombo("AssociatedID").setComboText(form._last_load_data.data.AssociatedID);

Small update:

My previous method worked great if my options had the same values for value and text. However, if the value was different from the text (such as the ID of a record in another table), the selected option wasn’t being displayed; instead the option’s value was being entered as the text.

This may not work for everyone’s specific cases, but since my form reloads the options after the form data loads (because one set of combo options depends on the value of another select), I added the following function for the onOptionsLoaded event:

	form.attachEvent("onOptionsLoaded",function(){
		if (typeof form._last_load_data !== 'undefined'){
			var index = form.getCombo("ShipMethodDetail").getIndexByValue(form._last_load_data.data.ShipMethodDetail);
			if (index >= 0) { form.getCombo("ShipMethodDetail").selectOption(index); }
		}
	});

As a result, the load function callback sets the text of the combo to the value loaded from the database, but if the value is found as an option in the combo list after the list has been loaded, it selects the correct option from the list. In this way, the value is both preserved and displayed properly whether or not it is in the list of combo options.

Thank you for sharing