Field_to_name_array result shown to user = readonly

How do I make a field readonly for users but also make the field so that it can be populated by field_to_name_array?

I want to use the field_to_name_array to populate a field in Module B
which I know how to do (see below)
and
I want the result shown to the user
which I know how to do
BUT
I want the result, when shown to the user to be readonly

and that last part I cannot make work with the first (2) parts

If I set the display field to readonly in editviewdefs using any of the three methods I have tried (see below), it prevents the field_to_name_array from populating the field now set to readonly

Here is what I have:

In my custom module AYU_Funds I am populating 2 fields:

  • fund_addr_city
  • fund_addr_street

by pulling their values from the Accounts module via a Relate field in AYU_Funds pointing to Accounts and using a field_to_name_array in custom/modules/AYU_Funds/metadata/editviewdefs.php

          1 =>
          array (
            'name' => 'parent_name',
            'studio' => 'visible',
            'label' => 'LBL_PARENT_NAME',
            'displayParams' =>
            array (
              'field_to_name_array' =>
              array (
                'name' => 'parent_name',
                'id' => 'parent_id',
                'primary_address_city' => 'fund_addr_city',
                'primary_address_street' => 'fund_addr_street',
              ),
              'additionalFields' =>
              array (
                'primary_address_city' => 'fund_addr_city',
                'primary_address_street' => 'fund_addr_street',
              ),
            ),
          ),

So far so good, all works well; the fileds in AYU_Funds are populated by the values in the Account to which the AYU_Funds module is related

I want the user to be able to see the results of the data pulled from Accounts but I do NOT want the user to be able to edit the fields showing the data.

I have tried three ways to make the fields readonly in the Edit View of AYU_Funds, all of which work to make the field readonly but all of which also prevent the field from being populated by field_to_name_array.

Here are the three methods I have tried to make a field readonly to users by adding to its definition (fund_addr_city shown - same thing tried with find_addr_street) in editviewdefs.php:

          0 =>
          array (
            'name' => 'fund_addr_city',
            'label' => 'LBL_FUND_ADDRESS_CITY',
            'type' => 'readonly',
          ),
          0 =>
          array (
            'name' => 'fund_addr_city',
            'label' => 'LBL_FUND_ADDRESS_CITY',
           ' displayParams' => array(
                'readonly' => true,
            )
          ),
          0 =>
          array (
            'name' => 'fund_addr_city',
            'label' => 'LBL_FUND_ADDRESS_CITY',
            'customcode' => '{$fields.fund_addr_city.value}'
          ),

All of the above do the same thing: make the field readonly but also prevent the field from being populated by field_to_name_array

How do I make a field readonly for users but also make the field so that it can be populated by field_to_name_array?

I have found a solution. I am not sure this is the best solution, so if anyone thinks of a cleaner way, please advise.

The key is to understand there are 2 conditions that would prevent a user from editing the contents of a field:

  • readonly: user can put the cursor in the field but cannot change contents
  • disabled: user can NOT put the cursor in the field (can NOT set focus on the field) and cannot change contents

Using readonly not only prevented the user from editing the field, it also prevented the system from editing the field contents via field_to_name_array

Using disabled prevented the user from editing the field but it did NOT prevent the system from editing the field contents via field_to_name_array

Unfortunately, although SuiteCRM has a built-in mechanism for making a field readonly by adding the displayParams entry to the field definition in editviewdefs for that module:

'displayParams' => array(
    'readonly' => true,
)

Suite CRM does NOT have an equivalent mechanism for setting the field to disabled

So instead, I added a customCode entry to the field definition in the editviewdefs.php file

          0 =>
          array (
            'name' => 'fund_addr_city',
            'label' => 'LBL_FUND_ADDRESS_CITY',
            'customcode' => '<div style="background-color:transparent; border-style:none";"><input style="background-color:transparent; border-style:none;" type="text" name="fund_addr_city" id="fund_addr_city" size="30" maxlength="255" disabled="true"></div>',
          ),

A couple of things to note:

  • before making any changes to the field, I did an inspect on the field to see what its current html setup was.
  • I took that setup and put it into the customCode definition and added the transparent background and no border (so it would not look like an editable field)
  • I then added the disabled=“true” element to the field definition

A Quick Repair and Rebuild and I had what I wanted:

  • The field could be populated by the field_to_name_array
  • The field could NOT be edited by users

If anyone comes up with a better solution, please advise