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
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)) ]
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.
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]
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.
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.
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.
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?
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.
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?
Both GetAsCSS and GetAsSVG can return any embedded formatting "tags" such as color that are part of the data stored in the field.
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.
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.
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.
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.
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.
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))]
Set Field By Name [$Table & "::" & $Field; TextColor( Get ( ActiveFieldContents ) ; RGB(0;0;0))]
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.