1 2 Previous Next 20 Replies Latest reply on Jan 29, 2015 6:59 PM by appt

    Script to change either text colour or button colour

    appt

      Title

      Script to change either text colour or button colour

      Post

      Hi, been away for a while need some help to make a form I have working easier to replicate.

      The form appears on an iPad and is made up of a number of text boxes (so it looks a bit like a spreadsheet).

      We have set it up using transparent buttons over the top of each text box that when touched cause the text underneath to change from black to red (indicating that task has been completed). A second touch will return it to black, a third to red etc.

      It works very well but is a pain to set up with loads of individual buttons tied to individual text boxes and code for each. I should add that the text boxes are actually fields so that I can use scripting to effect the change.

      I am wondering whether the buttons themselves could house the text and the text changes colour each time you touch the button.

      Failing that can anyone think of a way of doing it that isn't going to take me a lifetime?

       

       

        • 1. Re: Script to change either text colour or button colour
          schamblee

          You can use conditional formatting to change the color of the text and the text field and you don't need a button, when the condition is met then the color will change.   Right click on the field and then select conditional formatting.  http://www.filemaker.com/help/11/fmp/html/edit_layout.10.14.html 

          • 2. Re: Script to change either text colour or button colour
            philmodjunk

            I should add that the text boxes are actually fields so that I can use scripting to effect the change.

            If you have a text box (a box into which the user can enter data), it HAS to be a field, that's the only option in FileMaker.

            Here is a single script that could be performed by the OnObjectEnter script trigger to change the text color to Red:

            Set Variable [ $Table ; Value: Get ( activeFieldTableName ) ]
            Set Variable [ $Field ; Value: Get ( activeFieldName ) ]
            Set Field By Name [ $Table & "::" & $Field ; TextColor( Get ( activeFieldContents ) ;RGB(255;0;0)) ]
            Commit Records

            This same script can be used on as many different fields on your layout as you want.

            A more sophisticated script could "toggle" the field color back and forth between two colors.

            • 3. Re: Script to change either text colour or button colour
              appt

               

              Hi guys, thanks for the quick replies. Probably did not explain myself clearly though. Attached should be a screenshot of the working version. 

              Each text box is a actually a field autofilled when the page is first opened (thereby linking it directly to a specific student). Over the top of each field is an invisible button with the following script added.

              if [WrittenSample::A1N = 0]
              set field [WrittenSample::A1; textColor ( WrittenSample::A1 ; RGB (0 ; 0 ; 0 ) )]
              set field [WrittenSample::A1N = 1]
              else if [WrittenSample::A1N = 1]
              set field [WrittenSample::A1; textColor ( WrittenSample::A1 ; RGB (255 ; 0 ; 0 ) )]
              set field [WrittenSample::A1N = 0]
              end if

              A1N is also a field storing the 1/0 value

              So as you can see I need a script for each button, fields for each text value and also fields for the number value.
              That means in the new version 100 scripts each one slightly different (referencing a different field)

              I can do it and the current version works perfectly every time. It is just such a boring task to set up. Really it was just a thought as to whether anyone can see a way of doing it that won't send me round the bend. Can't see how the conditional formatting would be any quicker as I'd still need a reference number to store a 1 or 0 and then add formatting for each button, not much quicker than writing the scripts.

               

               

               

              • 4. Re: Script to change either text colour or button colour
                appt

                Here is the form when the user has touched the screen and highlighted where the children are.Touching any box again send it back to black. Teachers can print this off and instantly see where a student is.

                • 5. Re: Script to change either text colour or button colour
                  philmodjunk

                  Still don't see why the script I suggested couldn't be adapted to your use and gives you a single script that can be set up for every field and with no need for putting a button on top of it. Do you need that number field for some reason other than color display? (There are ways to detect the current color of the text in a field so you don't actually need a second field just to record whether the text is red or black...)

                  Another approach would use Set Field By Name, getField, and script parameters that use GetFieldName to pass the field reference to the script as a script parameter. Then you can make multiple copies of the same button and just update the script parameter to refer to different fields.

                  • 6. Re: Script to change either text colour or button colour
                    appt

                    Phil, I will try out your suggestion, but also need to set it back to black as explained, can you give me the heads up on that?

                     

                    • 7. Re: Script to change either text colour or button colour
                      appt

                      Ok, so that works to change the colour nicely. However in order to work I have had to make the field 'browsable' which introduces the possibility (unlikely though it is) that someone will change the text. So I will set them all to prohibit modification.
                      Looking good so far, if you can just help me with the reversion part, I should be up and running. As ever awesome Phil.

                       

                       

                       

                       

                      • 8. Re: Script to change either text colour or button colour
                        appt

                        Can't work out the 'if' part for the reversion, how do you compare the RGB value of the selected field with another RGB value?

                         

                        • 9. Re: Script to change either text colour or button colour
                          philmodjunk

                          Both GetAsCSS and GetAsSVG can return any embedded formatting "tags" such as color that are part of the data stored in the field.

                          So

                          PatternCount ( GetAsCss ( GetActiveFieldContents ) ; "color: #FF0000" )

                          will evalulate as True (nonzero result) if there is red text in the field.

                          The same expression will return 0 (False) if the text is black.

                          • 10. Re: Script to change either text colour or button colour
                            philmodjunk

                            Just saw your other post. If you take a closer look at the script, it bounces the focus back out of the field after the script runs so it shouldn't allow a user to modify the field contents, but you'll need to test the layout and remove all these fields from the tab order to keep FileMaker from moving the focus into one of them automatically.

                            • 11. Re: Script to change either text colour or button colour
                              appt

                              Ah, I forgot the CommitRecords step, thanks for pointing it out. That deals with that.

                              Will have a go at the last part today, many thanks, I'll let you know how it goes.

                               

                              • 12. Re: Script to change either text colour or button colour
                                appt

                                So according to Filemaker PatterCount returns a number as follows

                                "Returns the number of occurrences of SearchString in TEXT"

                                Which has me confused as you appear to be saying it gives a True/False evaluation?

                                When trying to use it you can see what happens in the attached screenshot.

                                • 13. Re: Script to change either text colour or button colour
                                  philmodjunk

                                  That should be Get ( activeFieldContents )

                                  In this type of Boolean expression, any calculation that returns a numeric result will evaluate as True for any value except 0. 0 evaluates as False.

                                  • 14. Re: Script to change either text colour or button colour
                                    appt

                                     

                                    So, for anybody else looking to create something similar here is the code as per Phil's instructions

                                    Set Variable [$Table; Value:Get ( ActiveFieldTableName )]
                                    Set Variable [$Field; Value:Get ( ActiveFieldName )]
                                    if [PatternCount ( GetAsCSS ( Get(ActiveFieldContents)) ; "color:#000000" ) = 1]
                                       Set Field By Name [$Table & "::" & $Field; TextColor( Get ( ActiveFieldContents ) ; RGB(255;0;0))]
                                    Else
                                       Set Field By Name [$Table & "::" & $Field; TextColor( Get ( ActiveFieldContents ) ; RGB(0;0;0))] 
                                    End If
                                    Commit Records/Requests [No dialog]


                                    Works like a dream. For us it will mean we can easily assess students using a matrix or mark scheme (this one is for junior schools but equally useful for us marking senior internal exams where in the past we would highlight individual criteria on a paper copy).

                                    Many thanks Phil.

                                     

                                     

                                     

                                     

                                    1 2 Previous Next