Indicator field on document

Hi

I am wanting to customise a doc according to the following …

  1. Add two custom fields : Date1 , Date2
  2. Date2 is calculated from Date1 in a certain way
  3. When Date2 is close ( i.e. within a set number days ; 2 days before Date2 ) I want to have a field next to the “Date2” field on the doc to be coloured red or highlighted
    or show some form of indication that is implediately visible to the user if the doc is opened.

I had a look at the list of fields but I couldn’t find something suitable for this function.

Any ideas ?

Addiional note
I intend using the “Listview settings” to change the colour of the doc in listview which will draw the attention of the user. But then when the user opens the actual
doc, the approaching “Date2” must be emphasized somehow

You could just apply css on the date2 field itself to highlight that it is approaching a deadline on refresh of the form.

frappe.ui.form.on("Doctype Name",{
    refresh(frm){
        if (condition){
            $('[data-fieldname="field_name"]').css('color','red')
        }
    }
})

Replace the field_name with the name of the field and set the condition (either through a frappe call to calculate the date or using js Date functions.