Read value from a dropdown when user selects an entry

If you want to do the following:
“Customer selects a dropdown. $dropdown->onChange(function ($v) { …}) he should get the selected dropdown value (id), lookup the entry in the model and get further fields from the id.” (original request by mkrecek)

Means: the customer changes the value of a dropdown and you want to get the selected id to do further requests.
You can do that as follows:

$jsCallback = \atk4\ui\JsCallback::addTo($this)->set(function($jsCallback, $data) use ($email, $phone) {
$model = new Customer($this->app->db);
$model->load($data['item']);

return [$email->jsInput(true)->val($model->get('email')), 
    $phone->jsInput(true)->val($model->get('phone'))];
        
}, [
 new \atk4\ui\JsExpression('{
         item: $(this).val()
   }')
]);
    
$customerid->onChange($jsCallback);