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 all, Im stuck in a issue. I have a form with a drop down field. All the other fields in the form are set to be hidden. And all these form fields depends on the drop down field. I have used the filterFields() method in the model to dynamically hide and show the form fields when the drop down option is changed. The problem Im stuck with is that, I want a option field to be selected by default so that when the create view/ update view page is loaded the filterFields() method should show the fields that depends on the default drop down option value.
Fields.yaml
fields:
product_mode:
label: Choose a Product Type
type: dropdown
default: parent
options:
parent: Parent
mobile: Mobile
web: Web
mobile_type:
label: Mobile Type
type: text
hidden: true
dependsOn: product_mode
web_name:
label: Website Domain
type: text
hidden: true
dependsOn: product_mode
title:
label: Title
type: text
hidden: true
dependsOn: product_mode
title_description:
label: Description
type: textarea
hidden: true
dependsOn: product_mode
filterFields Method - Inside Model class
protected $fillable = ['product_mode'];
public function filterFields($fields, $context= null)
{
if($this->product_mode == 'parent')
{
$fields->title->hidden = false;
$fields->title_description->hidden = false;
}
else
{
$fields->title->hidden = true;
$fields->title_description->hidden = true;
}
if($this->product_mode == 'mobile')
{
$fields->mobile_type->hidden = false;
}
else
{
$fields->mobile_type->hidden = true;
}
if($this->product_mode == 'web')
{
$fields->web_name->hidden = false;
}
else
{
$fields->web_name->hidden = true;
}
}
Last updated
1-1 of 1