Dynamically Setting Form Styles

The macro “sc_field_style” gives us the ability to change grid styles during events, however it doesn’t work for forms.

How do I change field styles on a form?

It doesn’t really make much sense that this only works for grids, but not forms.

-Thanks for any advice.

Yes you are right. But it’s fairly simple to do that using javascript. If you google this forum then you will find much samples. One sample can be found here:

http://scriptcase.aducom.com/cms/e107_plugins/faq/faq.php?0.cat.6.7

I’ve actually found this example before, but it doesn’t seem to do anything. I created a php method called coloration() which contains the following code:

$field = 'OrderStatus';
$color = 'red';
print "In color.";
if({OrderStatus} > 5)
{
	$color = 'green';
}
sc_ajax_javascript('set_color',array($field,$color));

I put the coloration() method in my OnLoad event like the forum suggested. Then I created a javascript method with 2 input paramaters and the following code:

document.F1[field].style.backgroundColor = color;

Alright, so I found out why it wasn’t working. Apparently the field name must be lowercase, despite the field name having capitalized letters in the development environment. Once I changed the field variable from OrderStatus to orderstatus, it worked!

It’s not working in situation when i want change color of field in multiple rows detail form in master/detail form

I am attempting to do this same thing… oddly enough when I add a Javascript Method to my form I dont see where I can sepcify two parameters… am I missing something?

This is very close to what I need to accomplish… the only issue I have is that I need the conditional code to be in the event based on data I am reading out of the database.
Would it be possible to use this method to create a PHP Method that you could call with values of “field” and “color” so I could change any field to any color within the events on a form?

Edit: Actually I could put my database lookup code in the method itself… but still the question remains… could the above be done? It might be very handy.

I got this working for my needs… and the fact that I have so many fields to check (Over 100) I am using a query to read the fields from the database then loop through them to color them… the only problem I have now is if a new field is added to the DB and doesn’t exist in the app then it breaks this coloring of the fields.

In my case new fields may be added and there will be a delay before I get the field added to the application in Scriptcase and I dont want it to break.

Is there a way to validate if a field exists in Scriptcase somehow?