Custom Javascript to act on generated DOM

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dugjohnson
    Member
    • Jan 2015
    • 38

    Custom Javascript to act on generated DOM

    I want to use jQuery to rewrite the href of a URL cell. I know how to write that code.
    I would like to be able to do it so that I don't have rebuild every time there is an upgrade.
    How do I include the external file? Where do I put it all?
    Can this be done?
  • yuri
    Member
    • Mar 2014
    • 8627

    #2
    It depends where you want to rewrite. If it's a field it can be easily achieved by defining a custom view in entityDefs. You just define custom view for a needed field.

    "view": "Custom:MyEntity.Fields.MyField"

    client/custom/src/views/my-entity/fields/my-field.js
    PHP Code:
    Espo.define('custom:views/my-entity/fields/my-field', 'views/fields/url', function (Dep) {
      
      return Dep.extend({
          afterRender: function () {
                 Dep.prototype.afterRender.call(this);
                 // HERE WRITE YOUR LOGIC
                 this.$el.find('a').attr('href', 'your_new_url');
                //
         },
      });
    
    }); 
    
    views/fields/url is an inherited class.
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    Working...