I just figured this out @geekroot. This is what happened to me and I have a similar issue.
You need to select the name column of your custom DocType as the first column. When selecting the item in the dropdown it’s “cleaning itself” because a validation function is run to validate the selected item. It validates the item by it’s first selected column which is expected to be the name aka the primary key of your table.
So your query should look like: select name, codigo_distrito, nombre_distrito from...
This is the relevant function. Is there a way to manipulate the value that is sent to this function to have other values but the name as the first column?
Or maybe there’s already an inbuilt solution for the validate_link function on server-side so it doesn’t assume that the value it is provided is the name of the doc but some other column?