type_ahead with a Valuelist problem

Hi All,
Can anyone help please.
I have a type_ahead field which is filled with a valuelist which returns an id but shows a description.

My problem is that if the user types something that is not currently in the valuelist I’m trying to catch the value typed in an onDataChanged method. Does anyone know how I access that information?
Many thanks in anticipation.
Caroline

If you attach a method to the onDataChange event of the field you get as parameters the old value, the new value and the JSEvent as follows:

function onItemCodeChange(oldValue, newValue, event).....

Unfortunately Nicola that holds the newValue that is to be saved back to the field and as I am saving the pk (id) but the user is typing a description then the newValue seems to be set to null and what was typed is lost :x .
Any other thoughts??

You’ll receive a onFocusLostEvent too.
Add it to your field and you’ll have your text if you do :

elements.FIELD.selectAll()
var text = elements.FIELD.getSelectedText()

(I tried this in smart client running 5.2.12)

Many thanks João if that works it would be fantastic :D

Help I must be going mad :x .

I changed your code and placed it in my global lost focus

	var form = event.getFormName();
	var field = event.getElementName();
	forms[form].elements[field].selectAll();
	globals.checkListTypedValue = forms[form].elements[field].getSelectedText();

Which works but unfortunately the onDataChange appear to be fired before the lost focus (which I guess makes sense), so I moved the exact code to my onDataChanged and that just gives an error

TypeError: Cannot read property “fldAuthorID” from undefined (C:_Data\Servoy\Trains\globals.js#183)

Any thoughts why??
Sorry for the stupidity I’ve been going round in circles for what feels like days!!

Add some breakpoints and see what the variables contain. I’m not seeing a way of this code giving that error.
Well… In some very strange cases I got forms without the “elements” property and that went away with a restart of the client/developer.

That’s a relief a restart did solve it. Many thanks for all the help.