• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

How to show/hide a module depending on if has data

Scheduled Pinned Locked Moved Solved Troubleshooting
3 Posts 2 Posters 162 Views 2 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    shicks
    last edited by Nov 20, 2024, 9:49 PM

    I have a custom module which displays a json list and is working fine. It uses node_help.js to fetch the json from a server.

    I would like to hide the module, header and all, if there is no data available. I’ve tried adding show() and hide() in the socketNotifcationReceived() :

    If (items.length> 0) {
    this.show();
    this.updateDom(animationSpeed);
    } else {
    this.hide();
    this.updateDom(animationSpeed);
    }

    The module will appear if there is initially items in the list. If I remove all items from the list, the module will “hide”. But if I add items to the server where the json is pulled, the module will not reappear.

    I’m guessing I don’t understand what all hide() does?

    Thank you for any guidance.

    S 1 Reply Last reply Nov 20, 2024, 10:10 PM Reply Quote 0
    • S Offline
      shicks @sdetweil
      last edited by Nov 21, 2024, 8:41 PM

      @sdetweil Thank you! Using developers tab and console.logs, I fixed the data coming in (driven on a timer). Once that was correct, your confirmation/explanation of show/hide made total sense!

      If (items.length> 0) {
      this.show();
      } else {
      this.hide();
      }

      Works great!

      1 Reply Last reply Reply Quote 0
      • S Offline
        sdetweil @shicks
        last edited by sdetweil Nov 20, 2024, 10:11 PM Nov 20, 2024, 10:10 PM

        @shicks 1st you don’t need the updateDom() calls… show will trigger that
        hide will not, because well, there is nothing to show, so no point updating

        now… what drives your socketNotification? (node_helper on a timer, or node_helper in response to module sendSocketNotification, driven on a timer)

        have you verified that the notification has arrived?

        if you use the developers window sources tab, you can put a breakpoint stop on the 1st executable line after it so see if it is called…

        I don’t see anything wrong with the objective

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        S 1 Reply Last reply Nov 21, 2024, 8:41 PM Reply Quote 0
        • S Offline
          shicks @sdetweil
          last edited by Nov 21, 2024, 8:41 PM

          @sdetweil Thank you! Using developers tab and console.logs, I fixed the data coming in (driven on a timer). Once that was correct, your confirmation/explanation of show/hide made total sense!

          If (items.length> 0) {
          this.show();
          } else {
          this.hide();
          }

          Works great!

          1 Reply Last reply Reply Quote 0
          • S sdetweil has marked this topic as solved on Nov 21, 2024, 8:44 PM
          • 1 / 1
          1 / 1
          • First post
            1/3
            Last post
          Enjoying MagicMirror? Please consider a donation!
          MagicMirror created by Michael Teeuw.
          Forum managed by Sam, technical setup by Karsten.
          This forum is using NodeBB as its core | Contributors
          Contact | Privacy Policy