0

Badges on TABS

Jacques TUR and others.

Using Ninext is it possible to add a badge to a TAB?  In the screenshot below you can see I have a TAB to view the notes related to a particular Location.  It would be handy if a badge on the TAB could show either the number of notes (count of the records in the view) or simply a badge to indicate that there are records.

10 replies

null
    • Ninox developper
    • Jacques_TUR
    • 1 yr ago
    • Reported - view

    I Allan, I am surprised by your question. You will find the answer in your previous message 馃

    https://forum.ninox.com/t/q6h0pvd?r=83h0rkv

    Does this help you?

      • Alan_Cooke
      • 1 yr ago
      • Reported - view

      Jacques TUR Ho dumb am I :-).  Set it up and it's working but......

      Using this:

      if count(NOTES) > 0 then
          function onUpdate(event : any) do
              {
                  caption: "LOCATION NOTES",
                  color: "#7e7e7e",
                  backgroundColor: "#00000",
                  tooltip: "Here you can see all notes related for this location only.  ",
                  badge: {
                      caption: "馃摑",
                      color: "#00000",
                      backgroundColor: "#ffffff"
                  }
              }
      end;
          true
      end

      Screenshot:

      Doing it this way the TAB is hidden if there are no records in the view which prevents the addition of a note (via + create record) should one be needed.

      Is there anyway to have it so that the TAB is always displayed with the badge only showing if there are in fact records in the view.  I have created a formula on the form that counts records but of course this does not help since the TAB is visible ONLY if there are records.

    • Ninox developper
    • Jacques_TUR
    • 1 yr ago
    • Reported - view

    In the "Display only If" trigger Ninox expects a true or false value to display or not display the tab. 
    Your function returns true only if count(NOTES) > 0. In all other cases, the tab will not be displayed.
    For this to work, you need to put the "if" condition inside the onUpdate function :

    function onUpdate(event : any) do
        if count(NOTES) > 0 then
            {
                caption: "LOCATION NOTES",
                color: "#7e7e7e",
                backgroundColor: "#00000",
                tooltip: "Here you can see all notes related for this location only.  ",
                badge: {
                    caption: text(count(NOTES)),
                    color: "#00000",
                    backgroundColor: "#ffffff"
                }
            }
    
        else
            {}
        end;
    end;
    
    true;
    
    
      • Alan_Cooke
      • 1 yr ago
      • Reported - view

      Jacques TUR Thanks - I tried this but the badge does not work if there is a note.  As you can see here there is 1 Loc. Note as per the formula top left.  The TAB however does not display the badge.

      Code:

      function onUpdate(event : any) do
          if count(NOTES) > 0 then
              {
                  caption: "LOCATION NOTES",
                  color: "#7e7e7e",
                  backgroundColor: "#00000",
                  tooltip: "Here you can see all notes related for this location only.  ",
                  badge: {
                      caption: text(count(NOTES)),
                      color: "#00000",
                      backgroundColor: "#ffffff"
                  }
              }

          else
              {}
          end;
      end;

      true;

      • Ninox developper
      • Jacques_TUR
      • 1 yr ago
      • Reported - view

      Alan Cooke Indeed, the function must always return a structure, otherwise the tab is hidden. Try this code:

      function onUpdate(event : any) do
          var badge := if 1 > 0 then
                  {
                      caption: text(count(1)),
                      color: "#00000",
                      backgroundColor: "#ffffff"
                  }
              else
                  {}
              end;
          {
              caption: "LOCATION NOTES",
              color: "#7e7e7e",
              backgroundColor: "#00000",
              tooltip: "Here you can see all notes related for this location only.  ",
              badge: badge
          }
      end;
      true
      • Ninox developper
      • Jacques_TUR
      • 1 yr ago
      • Reported - view

      Alan Cooke You can also look at the example of the Badges table in this database.

      Ninext 2.ninox 

      • Alan_Cooke
      • 1 yr ago
      • Reported - view

      Jacques TUR Thanks for getting back to me - tried your code and now the table/records will not load at all.  All other tables load as per normal but the LOCATIONS table remains like this:

      • Alan_Cooke
      • 1 yr ago
      • Reported - view

      Getting there, your code displays '1' regardless of whether there is a note or not.  In other words if there is no note(s) '1' still shows.  Remember I am displaying a table under the LOCATION NOTES TAB.

      In your code I do not see how the count of records in the LOCATION table is being retrieved.

      function onUpdate(event : any) do
          var badge := if 1 > 0 then
                  {
                      caption: text(count(1)),
                      color: "#FF0000",
                      backgroundColor: "#FFFFFF"
                  }
              else
                  {}
              end;
          {
              caption: "LOCATION NOTES",
              color: "#7e7e7e",
              backgroundColor: "#FFFFFF",
              tooltip: "Here you can see all notes related for this location only.  ",
              badge: badge
          }
      end;
      true

      • Ninox developper
      • Jacques_TUR
      • 1 yr ago
      • Reported - view

      Alan Cooke Could you send me one exemple of your code to try to fix this issue ?

      • Alan_Cooke
      • 1 yr ago
      • Reported - view

      Jacques TUR Hi there, sorry for delay.  For some reason I was blocked from posting.  I have sorted the problem out but I did notice that the 'count' does not actually count as such.  Regardless of the number of notes '1' is always reflected.  Because of that I have amended the code to this:

      function onUpdate(event : any) do
          var badge := if count(NOTES) > 0 then
                  {
                      caption: "馃摑",
                      color: "#FF0000",
                      backgroundColor: "#FFFFFF"
                  }
              else
                  {}
              end;
          {
              caption: "LOCATION NOTES",
              color: "#7e7e7e",
              backgroundColor: "#FFFFFF",
              tooltip: "Here you can see all notes related for this location only.  ",
              badge: badge
          }
      end;
      true

      It would be nicer to have an actual count of the notes but it's not critical.

      Thanks

Content aside

  • 1 yr agoLast active
  • 10Replies
  • 165Views
  • 2 Following