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?
pgr
11 February 2021 22:33
#2
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…
It’s not a logic hook, but you can customize the detail view, of course.
The simplest things you can achieve with just a Smarty formula in the vardefs.
For more complicated things… here is an example from a project of mine. It’s meant to show a Contact’s calculated age in place of his birthdate.
In file custom/modules/Contacts/views/view.detail.php
require_once('include/MVC/View/views/view.detail.php');
class CustomContactsViewDetail extends ViewDetail
{
/**
* @see SugarV…
@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
.
@peted
I recommend don’t change function ‘preDisplay’.
Make function ‘getMetaDataFile’ in file …/view.detail.php
/* add */
public function getMetaDataFile()
{
if ($this->bean->order_type == "Repair" || $this->bean->order_type == "Other" || $this->bean->order_type == "Stock") {
$oldType = $this->type;
$this->type = $oldType . 'ros';
}
$metadataFile = parent::getMetaDataFile();
if ($this->bean->order_type == "Repair" || $this->bea…
@peted
Without problems.
Add new form to the function ‘display’ to file …/view.detail.php:
public function display(){
if ($this->bean->order_type == "Repair" || $this->bean->order_type == "Other" || $this->bean->order_type == "Stock") {
$this->dv->formName='DetailView_ros';
}
parent::display();
}
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:
Write function preDisplay
to file view.detail.php
of your module and change data in array $metadataFile
.
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
}
}