Hide field in detail view conditionally

Hi
I’ve question about conditionally hiding fields (and labels) on detail view. On Accounts I want to hide ‘vat_c’ and ‘industry’ when ‘is_company_c’ is unchecked.

I have no problem hiding those fields on edit view (on_click method on ‘is_company_c’ field).

Any help?

I don’t have much time to explain, and I will be away for a week starting tomorrow, but I think this might set you going in the right direction…

@maciej.geciow

As a variant you can use different view forms for detailview. Where the field is_company_c will use as condition in function getMetaDataFile.


I know I can use 2 detail views (its my temporary solution). Question is can I do it using only one view?

@maciej.geciow

It’s good that you know about 2 views.
I can offer 2 other variants:

  1. Write function preDisplay to file view.detail.php of your module and change data in array $metadataFile.
  2. write javascript for changing data in frontend on form DetailView.

Perhaps there are more options

I use preDisplay to change text format but don’t know how to hide field (can hide text but not field with description).

@maciej.geciow
You can change fields in panels of view:

    public function preDisplay(){
        parent::preDisplay();
        foreach ($this->dv->defs['panels'] as $panel) {
            // your code
        }
    }