Field Style not working on Form

Michael_Nash
Tera Contributor

Good Day,

 

I have created a style and it woks on the list but not on the form please help.

 

Field name: Truck

Field name: javascript:current.u_truck.u_fuel_type=='BEV';

Style: background-color:#71E279

 

 

Michael_Nash_0-1698229771348.png

 

6 REPLIES 6

Danish Bhairag2
Tera Sage
Tera Sage

Hi @Michael_Nash ,

 

In order for it to work on form u need to write a onLoad Client Script. Please refer below as an example & modify accordingly.

function onLoad() {
    //Type appropriate comment here, and begin script below
   
 
        var eraststuscode = g_form.getControl('u_status');// replace it with ur backend name of the field
        
            eraststuscode.style.backgroundColor = 'lightgreen';
        
    
}

 

Thanks,

Danish

 

Hi @Danish Bhairag2  I have tried with the below code and its not working unless my script is incorrect.

 

function onLoad() {
    // Get references to the 'u_truck' and 'number' fields
    var truck = g_form.getControl('u_truck');
    var fuelType = g_form.getValue('u_truck.u_fuel_type');
    var ev = g_form.getControl('number');

    // Check if the 'u_fuel_type' field value is 'BEV'
    if (fuelType === 'BEV') {
        // Change the background color of 'u_truck' and 'number' fields to light green
        ev.style.backgroundColor = 'lightgreen';
        truck.style.backgroundColor = 'lightgreen';
    }
}

Hi @Michael_Nash ,

 

Can we try putting an alert on fuelType varaibel to check if we getting proper value?

 

Thanks,

Danish