I have a Dataobject in ModelAdmin with the following fields:
class NavGroup extends DataObject {
private static $db = array(
'GroupType' => 'Enum("Standard,NotStandard","Standard")',
'NumberOfBlocks' => 'Int'
);
public function getCMSFields() {
$groupTypeOptions = singleton('NavGroup')->dbObject('GroupType')->enumValues();
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Main', new Dropdownfield('GroupType', 'Group Type', $groupTypeOptions));
$fields->addFieldToTab('Root.Main', new Numericfield('NumberOfBlocks', 'Number of Blocks'));
return $fields;
}
}
If GroupType == "Standard"
I want the NumberOfBlocks
field to automatically hide so it's hidden from the user. This should happen dynamically.
Is this functionality available in SilverStripe, or do I need to add some custom JavaScript?
The Admin interface is bundled within the Silverstripe CMS but is most commonly used in conjunction with the cms module. The main class for displaying the interface is a specialized Controller called LeftAndMain, named as it is designed around a left hand navigation and a main edit form.
ModelAdmin provides a simple way to utilize the Silverstripe CMS UI with your own data models. It can create searchables list and edit views of DataObject subclasses, and even provides import and export of your data.
The main class for displaying the interface is a specialized Controller called LeftAndMain, named as it is designed around a left hand navigation and a main edit form. Starting with Silverstripe CMS 4, the user interface logic is transitioned from jQuery and jQuery.entwine , which is replaced with ReactJS.
A complete list of supported font icons is available to view in the Silverstripe CMS Design System Manager ModelAdmin uses the SearchContext class to provide a search form, as well as get the searched results. Every DataObject can have its own context, based on the fields which should be searchable.
You need to use the DisplayLogic module...
https://github.com/unclecheese/silverstripe-display-logic
Then your function can be written as...
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldsToTab('Root.Main',array(
Dropdownfield::create('GroupType', 'Group Type', singleton('NavGroup')->dbObject('GroupType')->enumValues())),
Numericfield::create('NumberOfBlocks', 'Number of Blocks')
->displayIf('GroupType')->isEqualTo('Standard')
));
return $fields;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With