8 Replies Latest reply on Sep 5, 2016 11:40 AM by golife

    Force a Button Bar segment to Active state via script step

    Jesse_Wright

      I'd like to force a Button Bar segment to Active state via script step, say after I use Go to Object to move the user to a slide/tab.

       

      If they are on the layout, they would use the Button Bar to navigate the tab/slide control (via Go to Object). No problem when the user manually clicks the button, the active state changes to show the segment as "pressed". 

       

      However if I navigate from another layout via script and put the user into a specific tab/slide, the default Active Segment remains "pressed", where I would like the user to see that the segment "pressed" represents the tab/slide they are in, so it is visibly active on the layout instead of the default segment. 

       

      I have tried Go to Object to select the segment after I have the user in the layout and have the specific tab/slide active, but it does not set the segment to active. It selects the segment and is visibly highlighted as selected. I can't figure out how to force it Active, not selected.

       

      I'd like to avoid doing something like hiding a duplicate Button Bar with the Segment I want active, setting a flag field to hide one bar to make the other visible when that Nav script is used (and clear the flag OnLayoutExit ).  Seems like a bit of a hack job to do something simple, but that was the first thing that came to mind.  Thought I ask here before proceeding.

       

      Thanks in advance!

      Jesse

        • 1. Re: Force a Button Bar segment to Active state via script step
          Jesse_Wright

          Here is a quick example file that illustrates my issue.

          • 2. Re: Force a Button Bar segment to Active state via script step
            Jesse_Wright

            Figured it out...

             

            • Add a new field to your table - it will be a temp field used to set the name of the segment you want active
            • Go into Active Segment in the Button Bar, Click Specify. In the calculation select the temp field you just created
            • Make sure all of the segments have a name
            • Set the name of one of the segments to the temp field & commit
            • The segments active state changes to what you specified in the temp field

             

            Hide the field off to the right out of your layout and then set the Active segment name as needed in your Nav scripts

            • 3. Re: Force a Button Bar segment to Active state via script step
              wimdecorte

              Doesn't sound like a solution that would work under all circumstances, what if a different user is on the same record but on a different segments and wants his to change state?

              - you might get a record locked conflict with other users

              - other user's buttom bar segment will change state without them doing anything

               

              As a rule you would want to avoid modifying a record just to make some UI widget work...

               

              Global fields could work in this scenario.

              • 4. Re: Force a Button Bar segment to Active state via script step
                Jesse_Wright

                I agree, just came to that conclusion as well. Thanks much!!

                • 5. Re: Force a Button Bar segment to Active state via script step
                  juz

                  Had the same issue, and tried this solution Jesse recommended, but using a global var as Win suggested.

                  E.g.

                  1. Set the Active Segment calculation to "$$ACTIVE.SEGMENT.NAME"
                  2. All segments have a name (that is, an object name specified within inspector, not to be confused with the button title that user sees specified within the button bar popup)
                  3. Set $$ACTIVE.SEGMENT.NAME to the object name of the segment I wanted.


                  Works like a charm for each record transition (e.g. using next/previous commands).

                  Thanks gents!

                  • 6. Re: Force a Button Bar segment to Active state via script step
                    JimmyCox

                    I do this in a few solutions. Have an onLayoutEnter script trigger set a global variable $$PanelNumber to 1, as the first slide panel is the default when you enter a layout and then have a calculation on the button bar to specify active state, something like:

                    Case (

                    $$PanelNumber = 1; "buttonbar.1";

                    $$PanelNumber = 2; "buttonbar.2";

                    $$PanelNumber = 3; "buttonbar.3";

                    $$PanelNumber = 4; "buttonbar.4";

                    $$PanelNumber = 5; "buttonbar.5"

                          )

                    then have an OnPanel switch script trigger on the slide panel with that sets $$PanelNumber to GetValue( Get ( TriggerTargetPanel) ; 1)

                    Seems to work fine, without having to set a field

                    • 7. Re: Force a Button Bar segment to Active state via script step
                      golife

                      Well, all this works within one file. But there is a problem for me switching layouts between different files.


                      But I have two separate files. I switch from one file to the other with a script that leads the user to the respective layout. Here the button bar is confused.

                       

                      I am setting the global variable $$activeSegment to the object name of the button bar segment.

                      This all works fine in one file.

                       

                      But when moving from one file to the other, even with an onLayoutOpen trigger setting the global variable $$activeSegment (in the new file), the active state is showing the state from the file from where the user left.

                       

                      Any suggestions?

                      • 8. Re: Force a Button Bar segment to Active state via script step
                        golife

                        After a lot of testing, I found that for this thing to work in separate files, it is also necessary to have a last "refresh window" stop. This finally worked.

                         

                        So, in my case, a simple button bar in two different files:

                        • Define object names for each segment button
                        • Set the active segment of the button bar to the global variable $$activeSegment
                        • Use the "onLayoutEnter" trigger of the layout to the script which sets the global variable to the segment buttons object name.
                        • Refresh the screen (important!)

                        IIn my case, the segment buttons have the current layout name, so I simply call for get(layoutname) and set the global to the layoutName which is the same as the segment button object name.

                         

                        (There are more dynamic button bars of course, but here I just came across the problem switching to layouts in other files)