This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hi I have a dropdown in fiedls.yaml
it have 2 options, and on edit page it always showing "option A" as the selected on page load even if it's option2 in DB.
type: label: 'app.plans::lang.plans.plan_type' oc.commentPosition: '' options: 1: 'A Plan' 2: 'B Plan' span: auto type: dropdown
how can I make the dropdown selectd option based on DB record on edit page load?
I'm also stuck with this: i've the getXYZOptions
and getXYZAttribute
methods in the model, but the edit page still show the first dropdown value.
Ah! I think i'm seeing the "problem" because i followed others code to have list columns display the attribute value instead of the key.
To fix this, just set another field name in your columns.yaml
such as {field}List
and add another method to your model, such as get{field}ListAttribute
for this specific case, here is mine:
public function getTypeAttribute()
{
$key = array_get($this->attributes, 'type');
return $key;
}
public function getTypeListAttribute()
{
$key = array_get($this->attributes, 'type');
return array_get($this->getTypeOptions(), $key);
}
1-4 of 4