How to set a negative number to RED color in a form field?

I have a field, the data type is Currency. I set Regional Setting to off. The change font color for negative number is missing. I am using the Scriptcase 9.6. I read the tutorial which show and allow to change font color for negative number. Am I missing something. Please advise.

Kindly advise how should I go about in doing the above. sc_field_color() is only applicable in Grid.

Thanks for your help.

It can be done with jQuery

//onLoad

if ({field} < 0)
{
?>
    
    <style>
       #id_off_field{
        	color: red !important;
       }
    </style>
    
<?php
}

Thanks for your reply. I am not familiar with jQuery you mean I have to create a javascript or php method? What is #id_off_field, where can I find this?

I am using form editable grid view.

Further explanation is greatly appreciated.

Normally you just have to copy the code in the onLoad Event

To find the id of a field you need to right click on your form and select INSPECT

Then you right click on the field you want and select INSPECT again, you now have access to the HTML code of your field. You should find id=“your_field”. If it’s not present on the current element it can be on one of the previous element

For an editable grid view you need to know what line you are currently processing, there a macro for that but I don’t remember is name. You can also do a loop counter yourself with a variable

Does not work. Is such a basic requirement and I don’t understand why Scriptcase does not have a macro for this.

They only have it for the Grid. :woman_facepalming:

Editable grid are more tricky

Can you share your code, so I look at what may be wrong

if ({glpv_det_amt} < 0)
{
?>

<style>
   # id_sc_field_glpv_det_amt_1{
    	color: red;
   }
</style>
<?php }

Inspect:

Row 1: id="id_sc_field_glpv_det_amt_1
Row 2: id="id_sc_field_glpv_det_amt_2
And so on …………

  1. How to loop through every row and new row?
  2. Can I use the above code on Ajax OnChange Event?

Thanks for your help.

The ID of my field start with id_read_on_ not id_sc_field_???

Create a variable to use as a counter in onApplicationInit

ex [row_number] = 0;

in onLoadRecord 

[row_number] += 1;
if ({glpv_det_amt} < 0)
{
?>
<style>
   # id_sc_field_glpv_det_amt_<?php echo([row_number]); ?>{
    	color: red !important;
   }
</style>
<?php
 }

in onNavigate

reset the variable
 [row_number] = 0;

You will also need to configure the global variable setting to the type input

  1. After keying in a negative number an output screen appear, why?
  2. The negative number in RED appear after I exit the form. Is it possible to show the negative number in Red when I move to the next row (new record)?
  3. May I know why I need to set the global variable to IN and not OUT?

Thanks.

1 - I don’t know, may be a syntax error or a conflict somewhere in the page. You can turn it off in application / settings / Notification settings

2 - This solution is static, to make it dynamic you need to create a field that will contain the row number and use AJAX to change the style of the field (onChange or onBlur)

in onLoadRecord 

    [row_number] += 1;
    {rownb} = [row_number];
    if ({glpv_det_amt} < 0)
    {
    ?>
    <style>
       # id_sc_field_glpv_det_amt_<?php echo([row_number]); ?>{
        	color: red !important;
       }
    </style>
    <?php
     }

Ajax Field glpv_det_amt, event onChange or onBlur

if ({glpv_det_amt} < 0)
{
?>
<style>
   # id_sc_field_glpv_det_amt_<?php echo({rownb}); ?>{
    	color: red !important;
   }
</style>
<?php
 } else {
?>
<style>
   # id_sc_field_glpv_det_amt_<?php echo({rownb}); ?>{
    	color: black !important;
   }
</style>
<?php
 }

3 - My mistake it should be OUT

  1. The output screen still appear it is because of the php echo () function? Where in the application / settings / Notification settings that I can mute the output screen?

  2. The above codes does not work in the Ajax field onBlur/onChange event/

Thanks for your help.