form field (select) color, background color, and lock!

hi guys, i was digging into form application and really need to know how to change the form field in type “select” change color, change background color based on condition?? i searched all macros but couldn’t find this fuction, and it is simple i think please advise

also want to lock another field in the form again from type select based on another select field in the same form, please tell me how to do so? i tried the “readonly” and it didn’t work in form…

kindly advise

Ok, here’s a pointer. I’ll let it up to you to adjust it to your needs.

Let’s assume we have two select fields {select1} and {select2}.

Create a Javascript method i.e. js_color_disable
document.F1[‘select2’].style.backgroundColor = ‘red’;
document.F1[‘select2’].disabled = true;

Create an onChange AjaxEvent on {select1}
If({select1} == 4) // or whatever your condition is
{
sc_ajax_javascript(‘js_color_disable’);
}

Enjoy the magic.

jsb

thanks jsbinca, your magic seems nice but didn’t work as expected, maybe i am doing something wrong

in my case i have field name: ds and field name: yt in form- multiple records… both type select (options are 1, 2 and 3 — foreign keys from other table )

i want if changed ds to 1 (actual value is “not valid”) then field “yt” background goes grey (#cccccc)
i crated the method this way:

the name: js_color_disable

code:

document.F1[‘yt’].style.backgroundColor = ‘red’; // i also tried ‘#cccccc
document.F1[‘yt’].disabled = true;

and in ajax events created new ajax event on field “ds” onchange…

in code:

If({ds} == 1)
{
sc_ajax_javascript(‘js_color_disable’);
}

but nothing changes, instead, i have the ajax loader “processing” keep in there in the screen all the time which is annoying!!

by the way: i have another normal events in the form that is re-load the whole fields if selected other field… which is working fine but also that annoying “processing” message stays on the screen but it does re-load the fields accordingly though

any hint? or the error location?

[QUOTE=itsme3;24189]
any hint? or the error location?[/QUOTE]

You change the background color for field “yt” and then disable this field?

either this or that! i am not able to do anyone of them, actually wanna lock the field, but instead, lets change its color!

i tried the readonly, it returns the field to its first option which i don’t want

is there a way to change a select field to specific option based on a condition? i tried all macros, couldn’t find so, something like if == x then set field {field} to “test”?

the re-load option of ajax just returns the field selection to the first one in the list of options, what if i want it to be exact one? what if i want to lock it as is? what if i want to change its background color? none is working for me, although the way jsb seems ok, i think i am missing something

i could use the readonly onLoad event but the ‘if’ function doesn’t work!! all the column is going into readonly regardless to if the firld ds is 1 or not! i am using a form in multiple records

Well, you didn’t mention the multiple records in your first post, that’s a whole different ball game.
I assume you want to disable/change color of a field in the same row. Now you have to figure out first in
which row you are to be able to change anything. So let’s go.
In order to do this I suggest you add a custom field of type integer i.e. {row_cnt}, and mark it hidden.
You also need to add a parameter to your Javascript method: row_nr

In the onScriptInit event initialize a counter: [counter] = 1;

In the onLoadRecord event:
{row_cnt} = [counter];
[counter] ++;

Edit your Ajax event to:
If({ds} == 1)
{
sc_ajax_javascript(‘js_color_disable’,array({row_cnt}));
}

Edit your js_color_disable method:
var field = ‘id_sc_field_yt_’+row_nr; // get the field to change
document.F1[field].style.backgroundColor = ‘red’; // or document.F1[field].disabled = true if you want.

Good luck.
jsb

I’m sorry jsb, couldn’t get it working :frowning: my bad
i tried all what your wrote, carefully… also this row_nr u mentioned ((( You also need to add a parameter to your Javascript method: row_nr)))
i assumed you typed it by mistake so tried to change it into row_cnt but no chance
i crated the field from sc (not in the database) and followed carefully each step… when starting the form to test it (in update more for example) it asked me for the [counter] and i put 1 or 2,… nothing really changes, no background color of field “yt” and not disabled for field “yt”

i know seems annoying maybe iam doing something wrong as well, i am not export, just trying to learn

[QUOTE=jsbinca;24200]Well, you didn’t mention the multiple records in your first post, that’s a whole different ball game.
I assume you want to disable/change color of a field in the same row. Now you have to figure out first in
which row you are to be able to change anything. So let’s go.
In order to do this I suggest you add a custom field of type integer i.e. {row_cnt}, and mark it hidden.
You also need to add a parameter to your Javascript method: row_nr

In the onScriptInit event initialize a counter: [counter] = 1;

In the onLoadRecord event:
{row_cnt} = [counter];
[counter] ++;

Edit your Ajax event to:
If({ds} == 1)
{
sc_ajax_javascript(‘js_color_disable’,array({row_cnt}));
}

Edit your js_color_disable method:
var field = ‘id_sc_field_yt_’+row_nr; // get the field to change
document.F1[field].style.backgroundColor = ‘red’; // or document.F1[field].disabled = true if you want.

Good luck.
jsb[/QUOTE]

For the counter, on the left menu go to Application -> Global Variables and mark the counter as ‘Out’.

The parameter row_nr is no typo it is intenionally.
Did you create the parameter for javascript method? See image below and read there:

http://www.scriptcase.net/docs/en_us/manual_mp.htm#form-applications/programming/methods

jsb

funtion_parameter.png

sorry jsb, i tried my best, without success :frowning: seems i am missing something, i sent you PM please see it if you can.
thanks

quick update, this worked with me on ajax onchange event guys, just follow exactly as jsb says and don’t forget to make the new field row_cnt part of the form :slight_smile: you can hide it though :slight_smile:

here is related topic, for form, perhaps we can solve this form missing stuff of sc by workarounds like this, as you know guys, it is available for grid (coloring, styling…) but not in forms!! why you no cool SC!? :cool:

http://www.scriptcase.net/forum/showthread.php?6434-again-multiple-records-form-discussion-and-selecting-working-row&p=24229#post24229

I have a similar problem, but seems to be more complicated: in the master/detail form I need to change the color of individual fields in the multiple rows detail form. I tried to adapt the solution proposed here, but it’s not working. Any ideas?