Waiting to execute javascript once page is fully loaded in Sugar 7

I need to hide a button in record view depending on the status

The problem I have is that the page needs to be fully loaded before I run the javascript to hide it

How can I do this?

I tried $( document ).ready(function() { but that doesnt work

Any ideas will be gratefull received

Sugar 7 is beginning to seriously depress me :(




Parents
  • Thanks

    I tried :

    $(document).on('load', function() {alert(1)})         
    $(window).load(function() {alert(2)})

    neither are triggered :(

    I think I may need to use $.when( to check if page is loaded but can't work out how at the moment

    This is incredibly frustrating 

    Is it only me that is finding doing the simplest things in sugar 7 is really difficult?

    I asked someone from Sugar and was pointed to the Adding Field Validation document but that is worse than useless for what I'm trying todo



  • Enrico

    I agree it is very useful for validation but it is not working for what I am trying todo which is hide a button depending on a value.

    Once I have got it working I will expand it to hide fields as well

    I tried adapting your code as follows

      myCustomLogicOn: function()    {
            
            if(this.model.get('phone_office') == '7777')
            {
                // log something on the console
                console.log('executing  my custom action');
                $('[name="validate_postal_code"]').hide();
              
            }
        },


    The function is executed but the button is not hidden

    I suspect it is running before the page is fully loaded

    I have proved that the code  $('[name="validate_postal_code"]').hide(); works by adding it to the click of another button 

    Am I missing something?


  • Hi Mike,    One way to do this is to manipulate the metadata before rendering the Record View.  You can remove the buttons you want to hide before rendering.      Using Enrico's sample code, in the example below, the "Share" button will be hidden in Cases Record View if the Priority is set to High:    ({      extendsFrom: 'RecordView',        initialize: function(options)      {          this._super('initialize', [options]);      },        _render: function()      {          this.myCustomLogicOnCases();          this._super('_render');      },        myCustomLogicOnCases: function()      {          // when case priority is High...          if(this.model.get('priority') == 'P1')          {              var thebutton = '';              var theidx = '';              // find the buttons index for the share button              _.find(this.meta.buttons, function(bn, idx) {                  if(bn.name == 'main_dropdown') {                          thebutton = idx;                          _.find(bn.buttons, function(bbn, idx_bbn) {                                  if(bbn.name == 'share') {                                          theidx = idx_bbn;                                          return true;                                  }                          });                          return true;                  }              });                if(thebutton != '' && theidx != '')              {                  //remove the meta                  this.meta.buttons[thebutton].buttons.splice(theidx, 1);              }          }      },        _dispose: function()      {          this._super('_dispose');      }  })    Hope this helps.    Cheers,  Felix  InsightfulCRM Australia
Reply
  • Hi Mike,    One way to do this is to manipulate the metadata before rendering the Record View.  You can remove the buttons you want to hide before rendering.      Using Enrico's sample code, in the example below, the "Share" button will be hidden in Cases Record View if the Priority is set to High:    ({      extendsFrom: 'RecordView',        initialize: function(options)      {          this._super('initialize', [options]);      },        _render: function()      {          this.myCustomLogicOnCases();          this._super('_render');      },        myCustomLogicOnCases: function()      {          // when case priority is High...          if(this.model.get('priority') == 'P1')          {              var thebutton = '';              var theidx = '';              // find the buttons index for the share button              _.find(this.meta.buttons, function(bn, idx) {                  if(bn.name == 'main_dropdown') {                          thebutton = idx;                          _.find(bn.buttons, function(bbn, idx_bbn) {                                  if(bbn.name == 'share') {                                          theidx = idx_bbn;                                          return true;                                  }                          });                          return true;                  }              });                if(thebutton != '' && theidx != '')              {                  //remove the meta                  this.meta.buttons[thebutton].buttons.splice(theidx, 1);              }          }      },        _dispose: function()      {          this._super('_dispose');      }  })    Hope this helps.    Cheers,  Felix  InsightfulCRM Australia
Children
No Data