Change field colour for deceased person

Viewing 11 reply threads
  • Author
    Posts
  • March 1, 2022 at 5:39 AM #46902

    John McArthur
    Participant

    Hi,

    I’m looking for a way to change a name field when a person is deceased.
    I currently have a ‘Full Name’ field (concatenated from other name fields, with a grey background) and a ‘Deceased’ check box.
    When the check box is ticked I would like the ‘Full Name’ field to have a black background with yellow text.
    Sounds simple enough but I’m a newbie to scripts so not sure how to trigger the change when the check box is ticked.
    Any help would be gratefully appreciated.
    Many thanks

    March 1, 2022 at 1:27 PM #46904

    Brendan
    Keymaster

    Hi John,

    I would suggest instead of a Checkbox, use a Pick List. In a Pick List you can assign colours to the values. Then on the Form properties, set the “Record Colour Field” option to be the field you’ve assigned that Pick List to. Then when you select a value from that Pick List in your record, Tap Forms will display a coloured bar next to the record. So then at a distance you can easily see which records represent deceased individuals.

    No scripting required.

    Thanks,

    Brendan

    March 2, 2022 at 5:27 AM #46907

    John McArthur
    Participant

    Thanks for that Brendan.

    I followed your instructions and the Pick list does show a small coloured bar to the left of the selection but when you click on the selection the coloured bar doesn’t appear in the field.
    It would be much easier if the record was blatantly obvious showing the person was deceased.
    ie the field background colour turns Black.

    I was playing around with script trying to achieve the colour changes but most web ‘help’ refers to HTML/CSS options. There is little help with regards to syntax for pure javascript, or there are conflicting ‘color’ coding syntax versions.

    See my feeble attempt at scripting below. :)
    Do I just need to correct the syntax for ‘colour’ related code for TF? …

    function Cl1_expired() {

    // Change text box colour when checkbox is ticked

    var cl1_deceased = record.getFieldValue(‘fld-8e6c8ac1b14446088d6f4443f103efd7’);
    var cl1_full_name = record.getFieldValue(‘fld-f86ccf72fcf848669d17db555ca697f3’);

    if (cl1_deceased = true) {
    // true condition;
    cl1_full_name.backgroundcolor = “black”;
    cl1_full_name.text.colour = “yellow”;

    } else {
    // false condition – do nothing
    }

    }

    Cl1_expired();

    March 2, 2022 at 8:59 AM #46909

    Daniel Leu
    Participant

    The Javascript API is documented at https://www.tapforms.com/help-mac/5.3/en/topic/javascript-api. Things like object.text.color or object.backgroundcolor are not supported. But there is record.setRecordColor('#cc9900');

    Maybe this works for you:

    function recordColorScript() {
    
    	const yes_no_id = 'fld-xxx'
    	const yes_no = record.getFieldValue(yes_no_id)
    	
    	if (yes_no){
    		record.setRecordColor('#00FF00') // green
    	} else {
    		record.setRecordColor('#FF0000') // red
    	}
    	document.saveAllChanges()
    }
    
    recordColorScript();
    March 2, 2022 at 10:56 AM #46911

    John McArthur
    Participant

    Hi Daniel,

    Thanks for that.

    I assume the ‘setRecordColor’ applies to the FLD stipulated in line 3?
    If this is the case then I actually need it to apply to a different field.
    The True/False field will be the trigger to change the other field.
    Also, what part of the field changes color? (background/text/both)

    Many thanks

    March 2, 2022 at 2:53 PM #46913

    Daniel Leu
    Participant

    This sets the background color of the record.

    March 2, 2022 at 3:04 PM #46914

    Daniel Leu
    Participant

    Just a little update to my field script:

    function recordColorScript() {
    
    	const yes_no_id = 'fld-xxx';
    	const yes_no = record.getFieldValue(yes_no_id)
    	
    	if (yes_no == "Yes"){
    		record.setRecordColor('#00FF00') // green
    		console.log("set color for yes")
    	} else {
    		record.setRecordColor('#FF0000') // red
    		console.log("set color for no")
    	}
    	document.saveAllChanges()
    	
    	return yes_no
    }
    
    recordColorScript();
    March 2, 2022 at 6:35 PM #46915

    John McArthur
    Participant

    Hi Daniel,

    Your script works perfectly and changes the colour of the record index listings.
    However, I would like only to change a specific field within the record layout.
    Sorry for not making myself clear.
    I have potentially 2 people in one record, ie Mr & Mrs, so I would only like to amend their specific ‘name’ entries to black/yellow if one of them passes away.
    Is it possible to amend the colours of a specific fields background & text?

    Many thanks

    March 2, 2022 at 7:55 PM #46916

    Sam Moffatt
    Participant

    I don’t believe there is an option to change the colours of fields, just records.

    March 2, 2022 at 10:54 PM #46919

    Brendan
    Keymaster

    That’s right, there’s no option to change the field value colours in specific records, that’s why I recommended using the Pick List option.

    March 3, 2022 at 8:23 AM #46920

    John McArthur
    Participant

    Thats a shame. It was only a ‘nice to have’ so I’ll have to get around it a different way.

    Thanks anyway guys.

    August 7, 2022 at 5:21 AM #47739

    Gregory
    Participant

    John, if it’s on a custom layout, you have an option.

    you could set up an Image field behind the text field you want to colour. set the text field’s background to off (transparent) and then populate the Image field with the colour you want (from a form/field that holds samples of the colour) whenever the operator clicks the Deceased checkbox.

    you might need to make sure that the colour images match the dimension proportions of the image field so that they fill the field.

    just be aware that clicking on the image field will open the colour image in a new window. I don’t think there’s any way to prevent a click getting to the image field.

    August 7, 2022 at 8:34 AM #47743

    John McArthur
    Participant

    Hi Gregory,
    Thanks for the suggestion.
    Decided just to have a tick box, much simpler…although less obvious.

Viewing 11 reply threads

You must be logged in to reply to this topic.