Skip to content

How to filter values from a dropdown field by taking into account value from another dropdown previously set #658

Answered by LukeTowers
RoKrypto asked this question in Q&A
Discussion options

You must be logged in to vote

You're looking for Field Dependency and model option methods.

Example:

fields.yaml

model:
    label: Model
    type: dropdown
version:
    label: Version
    type: dropdown
    dependsOn: model

MyModel.php

public function getModelOptions()
{
    return ModelModel::lists('name', 'id');
}

public function getVersionOptions()
{
    if ($this->model) {
        return $this->model->versions()->lists('name', 'id');
    }
    return Version::lists('name', 'id');
}

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@RoKrypto
Comment options

@LukeTowers
Comment options

Answer selected by LukeTowers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants