Uploaded image for project: 'Moodle app'
  1. Moodle app
  2. MOBILE-3457

Mobile init function return does not get passed to other handlers

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.9.0
    • Fix Version/s: None
    • Component/s: Remote addons
    • Labels:
    • Workaround:
      Hide

      You can just save the data in a global variable (window.whatever), although this probably isn't ideal if the user might have multiple sites.

      Show
      You can just save the data in a global variable (window.whatever), although this probably isn't ideal if the user might have multiple sites.
    • Affected Branches:
      MOODLE_39_STABLE
    • Sprint:
      Moodle App 3.9.3

      Description

      Documentation https://docs.moodle.org/dev/Mobile_support_for_plugins#Initialization says you can do this in a plugin init function:

      (begin paste)

      Finally, if you return an object in this init Javascript code, all the properties of that object will be passed to all the Javascript code of that handler so you can use them when the code is run. For example, if your init Javascript code does something like this:

      var result = {
          MyAddonClass: new MyAddonClass()
      };
      result;
      

      Then, for the rest of Javascript code of your handler (e.g. for the “main” method) you can use this variable like this:

      this.MyAddonClass
      

      (end paste)

      This does not appear to actually work. Here is examples from my code, running in a main menu handler.

      End of init.js:

      console.log('---Ran TEST code--');
      var result = {
          MyAddonClass: "TESTING"
      };
      result;
      

      Start of page .js:

      console.log('Test input values');
      console.log(this.MyAddonClass);
      console.log('DONE');
      

      Excerpts from console:

      Running against app tag v3.9.0:

      ---Ran TEST code--
      

      [...and when the page loads...]

      Test input values
       undefined
       DONE
      

        Attachments

          Activity

            People

            Assignee:
            jleyva Juan Leyva
            Reporter:
            quen Sam Marshall
            Participants:
            Component watchers:
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: