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

glowflame14614370
glowflame14614370

Can I show a list of my dropdown list options defined in backend model? In my form I have a dropdown with certain keys, so is it possible to display list of them with the "builder" component in page?

DMeganoski
DMeganoski

you can absolutely make a dropdown. Though I am not sure how you would go about this with builder.

If you wanted to do this manually, you would create a field on your model's 'create.yaml' or 'fields.yaml' and give it the type : 'dropdown'.


fields: {  }
tabs:
    fields:
        city:
            label: 'City'
            type: text
        country:
            label: 'Country'
            type: dropdown

You would then have to add a method to your model to return the options. It is named as such

get{field_name}Options() {} 

So following the above example


public function getCountryOptions() {
    return array('1' => 'USA', 2 => 'Canada');
}
david19236
david19236

Very nice. Thanks

1-3 of 3

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