Announcement

Collapse
No announcement yet.

Front-end readOnly and custom Handler

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Front-end readOnly and custom Handler

    Hi Yuri,

    it's a normal behaviour for a "readOnly" field ?

    EspoCrm 8.0.5

    step :
    myField : readOnly

    custom handler :
    myField = moment();

    result :
    on front-end : myField = today
    after save
    myField => null


    But if
    myField : not readOnly

    result :
    on front-end : myField = today.
    after save
    myField = today

    So, if a field is readOnly.. only back-end can modify ?

    Best Regards
    Last edited by item; 11-23-2023, 10:17 PM.

  • #2
    Hi,

    I'm not Yuri but I think I could help.

    This behavior is here since the v7.2.0 (https://github.com/espocrm/espocrm/releases/tag/7.2.0)
    As you can see in the devblog :
    Click image for larger version

Name:	image.png
Views:	230
Size:	97.0 KB
ID:	100051

    I had the same issue as you and I found a """workarround"".
    Instead of setting the field as "readOnly" you give it a dynamic logic where it's always in readonly (Like in the example below).

    Inside the "clientDefs" file of your Entity
    PHP Code:
    "dynamicLogic": {
            
    "fields": {
                
    "fieldName": {
                    
    "readOnly": {
                        
    "conditionGroup": [
                            {
                                
    "type""notEquals",
                                
    "attribute""id",
                                
    "value""-1"
                            
    }
                        ]
                    }
                }
            }
        }
    ​ 
    Regards,
    Firyo.

    Comment


    • item
      item commented
      Editing a comment
      Hi Firyo,

      thanks for info and nice workaround.. 
      ​​​​​​​
      Regards

  • #3
    Setting read-only values server-side is a more proper way. Maybe even setting in both the front-end and the back-end.

    If you are using a setup-handler, you can just call this.view.setFieldReadOnly('yourField', true);

    Comment


    • #4
      Hi Yuri/Devs,

      I am trying to implement read only fields using a view setup handler like you mention above (on version 7.5.5):

      Code:
      define('custom:handlers/mmx-camera-view-setup-handler', [], function () {
          class Handler {
              /**
               * @param {module:view} view
               */
              constructor(view) {
                  this.view = view;
              }
              process() {
                  console.log(`in process `,this.view);
      this.view.setFieldReadOnly('name', true);
              }
          }
          // Establish event support.
          Object.assign(Handler.prototype, Backbone.Events);
          return Handler;
      });​
      I'm getting an error:

      "jQuery.Deferred exception: this.view.setFieldReadOnly is not a function"

      I can't find an example of it in the codebase. Can you please help with what I'm doing wrong?

      Cheers,
      Clare

      Comment


      • #5
        Hi Clare,

        You need to define the type of the view you are targeting, try this below (replace the type e.f detail / edit etc)

        PHP Code:
        define('custom:handlers/mmx-camera-view-setup-handler', [], function () {

           class 
        Handler {

                
        constructor(view) {
                    
        /** @type {module:views/record/detail} */
                    
        this.view view;
                }

                
        process() {
                    
        this.listenTo(this.view'after:render', () => {
                        
        // Do something with view after render.
                        
        console.log(`in process ` , this.view);
                        
        this.view.setFieldReadOnly('name');
                    });
                }
            }

            
        // Establish event support.
            
        Object.assign(Handler.prototypeBackbone.Events);

            return 
        Handler;
        });
        ​ 
        Rabii
        Web Dev

        Comment


        • #6
          Thanks for the reply rabii. I tried this just now and am still getting the same error.

          I began creating a custom view for it yesterday instead and can successfully set the fields read only.

          Comment

          Working...
          X