This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

johnytributante17670
johnytributante17670

Hi I want to make some dropdown with value where first option will be NULL. Or default option equal NULL. This dropdown is optionally so user does not have to select this. So i have function which return me values:

public function getCityOptions() { 
$res = Location::get(['id', 'city'])->toArray();
 foreach ($res as $value) {
 $ret[$value['id']] = $value['city']; 
} 
asort($ret);
 return array_unique($ret); 
}

The code above return me array of cities. But i need one value which is equal to NULL. And How can i make this dropdown list where first value is null and then all others is a city?

In field.yaml i tried to use:

city_id:

label: City

type: dropdown

options: getCityOptions

default: NULL

But it not work for me.

Last updated

gush51974
gush51974

I faced the same task. Has anyone found a solution in 3 years? :)

daftspunky
daftspunky

Check out the emptyOption property when defining the dropdown.

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.