Hi,
I have a Dropdown and I want to get the name and id of my value from that list.
I can get the name but I can’t get the ID.
My model:
public function getLocationList() {
$usersMaster = UserLocations::find()->where(['account_id' => Yii::$app->user->identity->userProfile->account_id])->all();
$visibilities = Location::find()->where(['visibility' => 'on'])->all();
$usersMasterLocation = array();
foreach ($usersMaster as $Master)
{
array_push($usersMasterLocation, $Master->location_id);
}
foreach ($visibilities as $Visible)
{
array_push($usersMasterLocation, $Visible->location_id);
}
$locations = Location::find()->asArray()->where(['location_id' => $usersMasterLocation])->all();
return ArrayHelper::map($locations, 'location_id', 'name');
}
This populates my dropdown with the name value and that’s correct but when I select that dropdown
I want to get the location_id as well and not just the name.
This is my javascript in the view to see the result:
jQuery("#job-pickup_location").bind("typeahead:selected", function(ev, suggestion) {
console.log(suggestion.toSource());
});
but it’s printing only the name and not location_id