Autocomplete widget - save id of suggested and accepted value I'm writing a custom text field and widget module with ajax autocomplete from scratch. I want the lookup to work on one column, but I want another column's value (the looked-up item's id) to be saved as the field value in the node.

So, for example, user types for example Sams, they accept suggestion Samsung, but Drupal save its database identifier, say 145.

Conversely, when opening the node for editing, the saved value of 145 should be again looked up, converted and displayed as Samsung.

What is the key to get it working the Drupal way?
Use the Entity and Entity Reference modules to create the link between the two items, using this method means your selections will be available to other modules such as Views, Rules, etc.