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?


  • Felix

    Thanks that works to delete a button

    Really helpful

    I'd still like to know if there's a way to run the JavaScript when the page is fully loaded as hiding the button was an example

    I also need to add buttons using JavaScript, hide fields and other things

    Any ideas?


  • Guys that is really helpful :)

    Works well 

    I can probably build on this to do the other things I want like creating buttons programaticly

    Certainly cheered me up about Sugar 7 which will last until I hit my next problem :)


Reply Children
No Data