6 Replies Latest reply on Nov 11, 2016 12:52 PM by AA

    Drag and Drop portal (Excelisys)

    AA

      Hello,

       

      In the couple of days I started reading Excelisys' drag and drop solution (from Andy Persons) and found something strange in there script namely the _trigger = Self. https://www.excelisys.com/fm-tips/drag-and-drop-using-the-separation-model/

       

      Let ( [

      _trigger = Self;

      $$move_id = category

      ] ;

      id

      )

       

      This script is essential while we move the content of a container onto another container it picks up the targeted container's category, change the original category to a new category. However I am not sure how it does it perhaps the "_trigger = Self; " responsible for this but "_trigger" as a variable does not refer to any calculation it is just stand alone. They explain that it ensures that the calculation will run any time the field is modified. I think there is something in filemaker undocumented.

        • 1. Re: Drag and Drop portal (Excelisys)
          planteg

          Hi AA,

           

          if you look a the bottom of page 1 of 4, you will find a link to a PDF documentationd-and-d.jpg:

          On page 2, you will find the explanation, part of is:

           

          Next, we’ll define an auto-enter calculation for handle:

          Let ( [

          _trigger = Self ;

          $$move_id = category

          ] ;

          id

          )

          The purpose of this calculation is to populate the global variable $$move_id with the

          current record’s category. The first line, _trigger = Self, ensures that the calculation

          will run any time the field is modified. Finally, we return id to ensure that handle will

          always have something in it. This is crucial, since users can’t drag from an empty

          container. We’ll set the font size to 300 so that the text won’t appear in the small graphic

          size.

           

          Very interesting file.

          1 of 2 people found this helpful
          • 2. Re: Drag and Drop portal (Excelisys)
            AA

            Thanks, but it does not answer the question. PDF does not explain it.

            • 3. Re: Drag and Drop portal (Excelisys)
              planteg

              AA ,

               

              I will dig into the file and report back how it works.

               

              Stay tuned !

              • 4. Re: Drag and Drop portal (Excelisys)
                philipHPG

                An Auto-Enter calculation is recalculated any time a referenced field (that isn't in a related table) is changed.  So the _trigger = Self line simply has the Auto-Enter calculation reference the field itself so that the calculation is recalculated any time the field's value changes (in this case, when you drop something into the container). Dropping something into the container changes the value of the field. Then, by virtue of the _trigger = Self line, the Auto-Enter calculation is triggered to set the global variable (and change back the value of the field) so that seemingly the value never changes.

                 

                If you take out that line, the Auto-Enter calculation won't run when the value is changed (and you'll see a value change when dropping text into the container). Essentially the line's sole purpose is to flag to FileMaker that the Auto-Enter calculation needs to run whenever the value is changed. It isn't a hidden feature of FileMaker, it is simply a creative use of how Auto-Enter responds to field references.

                 

                Does that explanation help?

                • 5. Re: Drag and Drop portal (Excelisys)
                  planteg

                  AA,

                   

                  I don't know if you are familiar with the Let() function: to sum up, in the first part (between [ ]), you can set local variables that are used to make some calculation. Here _trigger is a local variable that will go away once the Let is finished. But $$move_id is a global variable that is set here. This one will continue living after the Let (that's perfectly Ok). The second part of the Let returns a value. In this occurrence, the returned value is id, which is a field in the same table, Move. So handle is set to the value of id. The important part is that $$move_id is set to the new category where the item is dragged.

                   

                  It may be hard to understand what going on. If you have FileMaker Pro Avanced, the start the debugger and see what happens in what order. That will help you understand the chain of events. If you look at the Layout in Layout mode, don't believe what you see: if you move around what's in the portal, you will find out that a portal row is made of two fields on top of each other. The field at the bottom has the trigger that moves the item.

                  2 of 2 people found this helpful
                  • 6. Re: Drag and Drop portal (Excelisys)
                    AA

                    Yes, this is what I have found interesting. Apart from other type of variables ($_local, $$_global ) Let function allows a third type of script variable that calls functions like _trigger = Self.

                     

                    Self = "Return the contents of the field/object"

                     

                    As my understanding it does not just ensure the recalculation but ensures to return the original content of the field but it replaces the content.

                     

                    When the cursor dragged on the targeted field it picks up (copy) the new content (category). It replaces the original content into an other one. OK I got it ! It returns the content of the object!

                     

                    The variable does not need to be a member of an equation/calculation in the script. The variable affects the whole script and ensures that the $_moveid = category has to return the content of the targeted field where the cursor is placed.    

                     

                    I think the most difficult to understand how Self works. We need something that helps to copy the new content of the targeted field something like GetLayoutObject Attribute function.

                     

                    I think it is clear, now, thanks for the help.