11 Replies Latest reply on Sep 23, 2014 1:09 PM by Jax

    copy email (or text field) to clipboard on button click

    Jax

      Title

      copy email (or text field) to clipboard on button click

      Post

      I'm trying to create an easy and space saving button (the @ sign in the screenshot) to copy the email address of a contact person to the user's clipboard. Contact persons can request to be anonymous (Yes/No), so I introduced an If.

      Here's my first buggy draft. For people that did not request anonymity, recorded in the lab selection::contact field (Yes/No), the email is displayed in the dialog but not copied to the clipboard. The button is on the lab selection list layout and sits in a portal collecting several user experiences (see image).

      If [lab selection::contact = "Yes"]
         Copy [Select; student::email]
         Show Custom Dialog ["Contact email"; "The student deposited this email:¶¶" & student::email]
      Else
         Show Custom Dialog ["Anonymous"; 'The student asked not be contacted."]
      End If

      Does this problem stem from the field being linked in through the portal but then it should also not be displayed in the dialog, shouldn't it? Do the copy to clipboard commands work equally well on different OSs (Mac 10.9.4 in my case). Will this button work via IWP?

      anonymous_yes-no%2C_email_to_clipboard_button.png

        • 1. Re: copy email (or text field) to clipboard on button click
          Jax

          I stumbled across a weird work-around. If I add the email field to the portal (david...@...), the clipboard is properly written to (see screenshot) and the email is selected.

          Not what I was looking for, since the whole point of the button is to save space as compared to displaying the entire email field.

          • 2. Re: copy email (or text field) to clipboard on button click
            philmodjunk

            The copy, paste and the script steps that start with the word "Insert" all require that the referenced field be physically present on the current layout. This is one of two reasons not to use copy in the first place unless you really need to. If you are moving this data to another location within FileMaker, don't copy and paste, use Set Variable to copy and Set Field to paste. That way, you avoid destroying any data the user may have previously copied to the clipboard.

            If you must copy to the clipboard, you can make the field extremely small or you can put the field on a different layout and have you script change layouts, copy the data and then change back.

            • 3. Re: copy email (or text field) to clipboard on button click
              Jax

              For a newbie user like me the small field solution or the loop to a different layout and back seem a little convoluted and unexpected.

              I may just go with a conditional display of the email field itself, which apparently can be done easily using hide criteria (http://bit.ly/1C4sw5z), alas that function has only been introduced in FM 13 and I run 12. Guess, I have to add an additional field, filled by a calculation using the yes/no boolean.

              Thanks, Phil, for the answer. You seem to be all over this forum. Impressive.

              • 4. Re: copy email (or text field) to clipboard on button click
                philmodjunk

                Why do you need to copy this data in the first place? This is normally only necessary if you are going to paste this data manually into another application as there are better ways to move data around within the Filemaker application.

                • 5. Re: copy email (or text field) to clipboard on button click
                  Jax

                  This is exactly what will be required by the users. They can look up comments and copy email addresses from Filemaker into their web mailers or email programs, if the feedback was not anonymous.

                  • 6. Re: copy email (or text field) to clipboard on button click
                    philmodjunk

                    The script to copy from a hidden layout can be very simple:

                    Go to Layout ['name other layout here" ...
                    Copy
                    Go to Layout [Original Layout]

                    The user never even knows that there was a change of layouts.

                    • 7. Re: copy email (or text field) to clipboard on button click
                      Jax

                      Ouch, another noobie snag! I just realized that the small field, copy to clipboard solution does not work in IWP, which is how I was planning to publish this database.

                      Well, gotta think of a different solution. I will probably create a new field with mailto:name@server.com data which together with the Open URL script command does work in IWP.

                      • 8. Re: copy email (or text field) to clipboard on button click
                        philmodjunk

                        The size of the field should not be an issue. But copying to the clipboard at all might be a problem due to using a web browser  as your user interface. You may need to expose this data in a text field where the user can manually copy the data for pasting. Just make it a calculation field that they can copy from so that they can't accidentally change the data.

                        • 9. Re: copy email (or text field) to clipboard on button click
                          Jax

                          Or that would be an easier solution occupying a little more interface space depending on the field size. It has the advantage of being simpler. If mailto: is not set up properly in the browser, the email address will end up in the middle of nowhere. On the other hand, on my system (FM12, IWP, and the latest FF) the field has to be full size since it does not expand upon selection (if it's read-only access) and I can only select what I see. Using shift and cursor keys works, but not everybody will find this trick.

                          • 10. Re: copy email (or text field) to clipboard on button click
                            philmodjunk

                            The small size would only be for a script to use to copy the data. In that context, the size of the field should not make a difference--assuming that the script can copy this data at all in an IWP context. If the user is to manually select and copy the data, you'd need a field that is large enough to properly select the contents.

                            • 11. Re: copy email (or text field) to clipboard on button click
                              Jax

                              In the end, not even the Open URL / mailto: solution worked for me since IWP did not take into account from which button in the portal the script was triggered. I often got email addresses from a previously selected entry that didn't match the one the mailto button was triggered from.

                              Ultimately, I resulted to just displaying the entire email field for users to highlight and copy the low tech way.