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 Children
  • Hi All Developers,

    i have the same issue, i have applied readonly option to my custom field in verdef
    it is working fine, but in list view user are able to edit the field.

    could  you please suggest me the solution, i need also to readonly the field on list view

    Any suggestions would be appreciated. 

     

  • 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.

  •  
    i have tried the above solution in my local development system, but my custom field is still editable on list view, what should i do now, please suggest

  • Hello ,

    It seems like you're encountering a challenge with your custom field's editability on the list view despite implementing the provided solution in your local development system.

    Have you tried this

    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.

    Or you want to add the read-only to the field using code.