How to make a custom field read only in detail view??

How to make a custom field read only in detail view??

Thanks!!

Parents Reply
  • Hello ,

    You go to this path /custom/modules/<your ModuleName>/clients/base/views.

    If the "recordlist" folder exists within the specified path, and if that folder contains the "recordlist.js" file, it is necessary to incorporate custom code.  Conversely, if the "recordlist" folder is not present, you must create this folder within the "views" directory. Subsequently, inside the newly created "recordlist" folder, include a file named "recordlist.js." This process ensures the proper organization and inclusion of the required files for the intended functionality.

    After that, you need to add some code here

    ({
        extendsFrom: 'RecordlistView',
        initialize: function (options) {
            this._super('initialize', [options]);
            this.listenTo(this.collection, 'data:sync:complete', this.listViewFieldReadonly);
        },
        
        listViewFieldReadonly: function () {
            _.each(this.meta.panels, function (panel) {
              _.each(panel.fields, function (field) {
                if (field.name == "custom_fieldName") {
                  field.readonly = true;
                }
              });
            });
        },
        
    })


    Alternatively, you can achieve the same outcome through the studio. Navigate to "Admin -> Studio -> <Your ModuleName> -> Fields -> <Your fieldName>." Within this section, uncheck the "Mass Update" option. Subsequently, observe an option labeled "Required Field" that appears just beneath; check this box. Finally, save the field configuration. This process will automatically render the field as read-only across all relevant areas.


    Hope this will work for you.

Children