Fix #361 for autocomplete freetext

Please review and integrate, thanks!