Announcement

Collapse
No announcement yet.

Custom detail.js onChange event

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

  • Custom detail.js onChange event

    Hi,

    RESOLVED..
    my apology, this was a old beforSave hook who empty my field.

    so this function perfecly

    PHP Code:

    define
    ('custom:views/meeting/detail', ['crm:views/meeting/detail'],  function (Dep) {
        return 
    Dep.extend({
            
    setup: function () {
                
    Dep.prototype.setup.call(this);
                
    this.listenTo(this.model'change:parentId', function () {
                    if (
    this.model.get('parentId') && this.model.get('parentType') =='Patient' && this.model.hasChanged('parentId') ){
                        
    this.ajaxGetRequest('Patient/' this.model.get('parentId')).then(function (patient) {
                            
    let place =  patient['addressStreet'] +' ' patient['addressPostalCode'] + ' ' patient['addressCity'];
                               
    this.model.set('place'place );

                            
    this.model.save({placeplace}, {patchtrue});  
                            
    this.trigger('after:save'this.model);  

                        }.
    bind(this));    
                    }
                }, 
    this);
            },
            
    afterRender: function() {
                
    Dep.prototype.afterRender.call(this);
            },        
        });
    });
    ​ 
    Last edited by item; 03-15-2023, 08:03 PM.

  • #2
    Hi, 3 like nice..

    but as my skill is 0 in front-end .. how make this work in all views ?
    modal, edit, small ... create, .. maybe other .. it's out of my skill :s

    Really, need to understand where put ..
    record view, field view, .. detail, small, ...
    so this work in any view .. (not inline this i have understand i think)
    it's too my english


    Last edited by item; 03-20-2023, 11:41 PM.

    Comment


    • #3
      Hello item

      These are the default front end view classes: (you can change them in the entity's clientDefs.json script)
      Code:
      views: {
          "list": "views/list"
          "detail" : "views/detail"
      },
      recordViews: {
          "list" : "views/record/list",
          "detail": "views/record/detail"
          "edit" : "views/record/edit",
          "detailSmall" : "views/record/detail/small",
          "editSmall" : "views/record/edit/small",
          "kanban" : "views/record/kanban"
      }
      Looking at your code above, I would suggest implementing the functionality in the "recordViews" "detail" view which actually controls the screen section where the entity data (fields) are located.

      Please see the diagram below:

      Click image for larger version

Name:	Detail Display Nested Views.png
Views:	293
Size:	22.6 KB
ID:	89918

      Something like this: (I didn't test it but should work well)
      PHP Code:
      define('custom:views/meeting/record/detail', ['crm:views/meeting/record/detail'],  function (Dep) {
          return 
      Dep.extend({
              
      setup: function () {
                  
      Dep.prototype.setup.call(this);
                  
      this.listenTo(this.model'change:parentId', function () {
                      if (
      this.model.get('parentId') && this.model.get('parentType') =='Patient' && this.model.hasChanged('parentId') ){
                          
      this.ajaxGetRequest('Patient/' this.model.get('parentId')).then(function (patient) {
                              
      let place =  patient['addressStreet'] +' ' patient['addressPostalCode'] + ' ' patient['addressCity'];
                                 
      this.model.set('place'place );

                              
      this.model.save({placeplace}, {patchtrue});  
                              
      this.trigger('after:save'this.model);  

                          }.
      bind(this));    
                      }
                  }, 
      this);
              },
              
      afterRender: function() {
                  
      Dep.prototype.afterRender.call(this);
              },        
          });
      });
      ​  ​ 
      Please see this posting for a quick description of what part of the screen is controlled by each view class https://forum.espocrm.com/forum/deve...hing#post61108
      Last edited by telecastg; 03-24-2023, 06:11 PM.

      Comment


      • #4
        I realized that I had not responded to your question of how to implement this functionality across all types of views, but that is a little more elaborate so I posted a tutorial that I think will be easier to follow.

        This project describes how to implement a custom functionality (update the value of field "place" in Meeting when the Meeting's parent entity changes) across all types of Meeting views. Background information: Based on the metadata file application/Espo/Modules/Crm/Resources/metadata/clientDefs/Meeting.json and the

        Comment

        Working...
        X