Use the [logic] key in varsdefs

Hi,

I trying to add some custom conditional fields visibility in the documents module. In the developer documentation section, I found this tutorial that seem to be exactly what I try to do : Adding Custom Field Logic :: SuiteCRM Documentation
The logic extension.

So I created the conditional field and some testing field with Studio, then added a new blank file in public/legacy/custom/Extension/modules/Documents/Ext/Vardefs/_add_documents_type_field_logic.php
and finaly add this code :

  //this is to be sure that my changes are applied, after the repair and rebuild hit :
$dictionary['Document']['fields']['t1_champ1_c']['default'] = "hello world 3";
//this is the logic statement, from the topic. As I anderstand, if the field "type_c" is setted to "piece_id", the field "t1_champ1_c" has to disappear. 
$dictionary['Document']['fields']['t1_champ1_c']['logic'] = [
     'display'=>[
        'key' => 'displayType',
        'modes' => ['detail', 'edit', 'create'],
        'params' => [
            'fieldDependencies' => [
                'type_c',
            ],
            'targetDisplayType' => 'none',
            'activeOnFields' =>  [
                'type_c' => [ 'piece_id']
            ]
        ]
     ]
 ];

the default value is well setted, but the logic described in my comment don’t work. Do I missing something?

The type_c field is a simple choice list type.

Did you run Quick Repair and Rebuild?

Thank you for reply. Yes I did : to be sure I set the default key every time I make a change and I can see the change, the default value of the field is updated (see my code).

Usually, conditions like that will be added to the specific view you need.

Check here for some ideas:

But In the documentation I mention (Adding Custom Field Logic :: SuiteCRM Documentation) , it is say that we must add this in vardef :

The following code block shows an example of the configuration we need to add to the vardefs in order to get the logic described on the previous section

?php

...

        'priority' => array(
            'name' => 'priority',
            'vname' => 'LBL_PRIORITY',
            'type' => 'enum',
            'options' => 'case_priority_dom',
            'len' => 100,
            'audited' => true,
            'comment' => 'The priority of the case',
            'logic' => [
                'display' => [
                    'key' => 'displayType',
                    'modes' => ['detail', 'edit', 'create'],
                    'params' => [
                        'fieldDependencies' => [
                            'state',
                        ],
                        'targetDisplayType' => 'none',
                        'activeOnFields' =>  [
                            'state' => [ 'Closed']
                        ]

I am quite unsure about how to do this for SuiteCRM 8. The docs are not clear about using “Logic” as a key in the field’s dictionary… Those “…” in the docs are really mysterious :frowning:

Hi @Cawet,

The first code snippet you sent is ok.

The problem is that the ‘logic’ entry only applies to Suite 8 views and the documents module is currently running in the “Classic View”.

PS: I’m sorry but I may not reply back so soon, or at all. Quite busy at the moment.

1 Like

Ho so I can’t use this for the Documents module and I have to use some javascript instead? (fare enought for me)

PS: don’t be sorry, we can’t be everywhere, thank for your time :]

Hi @Cawet,

Yes, while the Documents module is on “classic view” mode you need to the change in a legacy way.
Following the suggestion @BrozTechnologies made may be an option, depending on your requirements.

All right, I use some javascript instead, I’ll do it in a proper way next time =D

Thank you for the explanation !