5 Replies Latest reply on May 15, 2012 10:53 AM by TellyShammas

    Lock a text field's text format

    jebber6685

      Title

      Lock a text field's text format

      Post

      I want to lock some of my text fields so that when I paste text from an email or other document, the text data entered will take on the format specified by the field and NOT where I copied the data from. 

      I did a search for this and the answer was give as;

      Set up an auto-enter calculation that strips out all user added text styles:
      TextFormatRemove (Self)
      and clear the "do not replace existing value" option.
      Now the only text formatting that will remain after the user exits the field will be the styles you apply to the field while in layout mode.

      My problem is that I do not understand how to apply this auto-enter calculation to a text field. Can someone give more detail 
      on how you implement this auto-enter calculation to a text field?
      Any help here would be greatly  appreciated.

      I have FMPro Advanced 12 v1
      OS - Windows Vista on desktop, Windows 7 on laptop

        • 1. Re: Lock a text field's text format
          philmodjunk

          Open manage | Database | fields from the File menu.

          Find your text field

          Double click it to open the Field Options Dialog.

          Click the auto-enter tab in this dialog.

          Click the "by calculation" option to open the specify calculation dialog.

          Enter: TextFormatRemove ( Self )

          And click OK. ("Self" is a special name you can use here so that the expression automatically refers to your field without needing to enter the actual field name in place of self. This makes it possible to set up utility expressions like this one and copy and paste them into multiple fields without having to edit them to add the specific field name.)

          On the auto-enter tab, you'll find a check box for "do not replace existing value..." clear this check box. Since this calculation replaces the data entered by the user with the modified (format removed) data, it won't do anything unless this option is cleared.

          • 2. Re: Lock a text field's text format
            jebber6685

            That is great!! Works like a charm, 

            • 3. Re: Lock a text field's text format
              TellyShammas

              Hello,

              I have been searching for a solution like this and was glad I stumbled upon this post... only to find out it doesn't quite work for me :)

              I am able to succesfully remove the text formatting of a text field using this calculation, however, the field I need to remove the format from is a lookup field. If I go to the Auto-Enter Options of the field and select "Calculated Value" it automatically removes the "Looked-up value."

              Any way to change the format of a lookup field, as in, to bring over the data only and not any of the formatting?

              Also, on a somewhat related note, is there a way to remove spacing from a lookup field? For example, if in Field A in Table 1 I have this text:

              "

               

              Text"

              can this be "flushed" to the top in Field B of Table 2 (lookup) as:

              "Text"?

              I apologize if any of this has been answered in previous posts, though I couldn't find anything after thorough searching.

              Thanks in advance to any who can help!

              Using FM11.

              • 4. Re: Lock a text field's text format
                Sorbsbuster

                You could set a script trigger to apply on ObjectModify, or ObjectExit on that field.  You could make the script set that field to itself, but with the step:

                Set Field ( ThatField ; TextFormatRemove ( ThatField )

                 

                In the original table (the one the data is held in for the lookup) you could set an auto-enter calculation on that field, similar to TextFormatRemove, but with:

                Filter ( ThatField ; "abcdefghijklmnopqrs...etc" )

                and it will replace itself with only those characters in your filter list.

                If you test your auto-enter on one record first you can then use the same function to do a 'Replace Field Contents' on your existing records.

                • 5. Re: Lock a text field's text format
                  TellyShammas

                  Thanks Sorbsbuster!

                  I used your feedback to come up with a similar solution that I believe will work for now.


                  I didn't want to modify the original table and field, as special formatting is often used and required there... the tricky part was that even in the other table where the lookup field is used, special formatting is sometimes required as well, just in a different way and not as often. Having the script perform the TextFormatRemove calculation on ObjectModify/Entry/Exit/etc would eliminate the possibility of ever being able to format that field in the future.

                  The workaround was embedding the TextFormatRemove calculation into the script which initiates the creation of a new record and thus causes the lookup fields to be filled. Thus, when a new record is created and the data is pulled via lookup, the field in question has any prior formatting stripped, yet can be formatted later if needed. I also embedded a subsitute calculation for line breaks (found answers in other forum posts), as Trim/TrimAll would not work as needed. That also solved my other problem with all the extra spacing.

                  Hopefully some (or all) of this will be helpful to other users.

                  Thanks again for the help!