again, multiple records form - discussion and selecting working row...

hi guys,
with the big help of jsb (he is really great :slight_smile: ) I could get this work
http://www.scriptcase.net/forum/showthread.php?6418-form-field-(select)-color-background-color-and-lock!

now i can ON AJAX ONCHANGE event to be able to change the background color and disable a field/fieldsā€¦ the trick is to specify the row counter that you are working on, otherwise any change in the field will disable/ change color of all the form (in multiple records) so it is uselessā€¦

now, i have something like this:

If({field1} == '1')
{
sc_ajax_javascript('js_color_grey',array({row_cnt}));

I have also a js method says:

var field1 = 'id_sc_field_field1_'+row_nr;
document.F1[field1].style.backgroundColor = '#cccccc';

add to that, the parameter of the js that i added ā€œrow_nrā€ and the new field that says row_cnt and the counter variableā€¦ just as jsb explained in my previous postā€¦

HOW about making this work onLoad? i tried the same and read in macros, found that this macro only works for ajax, how if i want to onLoad checks my field (fields) and apply those disable/background colors accordingly?

i tried to create a php method and failed,

i tried to use sc_field_disable it works fine on condition, but it disables all rows in the form, without being able to distanguish which row to work onā€¦

please, i need the form to also color/disable specific fields based on other fields conditionsā€¦ not only on ajax on changeā€¦
i mean in multiple records form, and to understand in which row that is appliedā€¦

if i can further to set specifc option/data in some field based on other field selection, this will be really great

all your help is appreciated guys, i know do annoy sometimes, believe me i am sure many of my level people will search for such stuff :slight_smile: :slight_smile:

onLoadRecord:
If({field1} == ā€˜1ā€™)
{
sc_ajax_javascript(ā€˜js_color_greyā€™,array({row_cnt})); //you actually donā€™t need the row number in this case, but it doesnā€™t hurt.
}

jsb

perfect, just perfectā€¦ i almost swear that i tried it yesterday and didnt work, thought of ajax should stay in ajax eventsā€¦ hence, it can be called magic

now even form has flexible stuff like grid :slight_smile:

thanks again, and always dear, appreciated your continuous support

jsb, sorry to be so annoying, that really works fine for coloring but when disabling fields in the multiple records form case, i found this:
1- coloring is fine, works ok as supposed to
2- once ā€œdisableā€ is used in one of the fields, it is working as supposed, but, whenever the record is being updated (any other field in the row, or even if only selected the row and didnā€™t change anything in it) then it is storing the value ā€œ0ā€ to the database! which is inconvenience

i changed all my primary keys of the tables that get the data from to id= ā€œ0ā€ as the first record so some scenarios reset to 0 is actually helping because i am locking another field i the same row so i will make it as ā€œ0ā€ in the db and that is fine, but for most scenarios, i want to lock ā€œdisableā€ field not to be changed from 1 or 2 or 3 for example, alternatively, if i want it to be 0, then i am using "reload all other fields onChange by ajax or the last field of the rowā€¦) r

So, in short, if row is saved and there is a disabled field in it, it will store it the value ā€œ0ā€ to the databaseā€¦ and hence, as it is onLoadRecord, it is all messed up once the form is re-loadedā€¦ because that ā€œdsā€ field which is supposed to be disabled and its value is 2, it is being 0ā€¦ so there is another js_method makes it green colorā€¦ and hence it is also enabled it for selection!! because it lost the condition if ({ds} == 0) { enable the the field, and make it green} and another condition says if ({ds} == 1) {condition here to make the field disable and make it white} + ({ds} == 2) {condition here to make the enabled and the color blue and make it white} ā€“ every condition is in individual js_method as you thought meā€¦

i double checked all methods and and conditions, seems okā€¦ when removed the ā€œdisableā€ functions from onLoadRecords then it works, but i want them really disabled and keep disabled if changed another values in the row!! not to be reset to 0 if they are disabled!

hope you understand my issue and forgive my englishā€¦ if you donā€™t get my point, please tell me i will make some screenshots or explain it differentlyā€¦

Mike

Oooops!
Completely forgot that the value of a disabled select field is not submitted.
So the easiest is to enabled them just before submitting the form.

Click on Javascript in the Form Settings menu (left panel).

Select the object: Form
Select the event: Submit

Click on Edit

Put in the following code:

var table = document.getElementById(ā€˜hidden_bloco_0ā€™); //table-id
var r_count = table.rows.length; // number of records

for(var i = 1; i < r_count; i++)
{
document.F1[ā€˜id_sc_field_gsa_ā€™+i].disabled = false;
}

Click on Update

That should do it (I hope). :slight_smile:

jsb

hi dear, thank God you got my point without racking this time :smiley:
ok i tried the code and put it exact as is, what happens is the update button of the field is being disabled at all, the form as you know is in multiple record mode, and i am working on update modeā€¦ so when selecting a row to update it, the button is inactive, no response at all!!

i tried also to change the id_sc_field_gsa to id_sc_ds_gsa (the field in my case) but also, no response of the update button at all!

if you hover on the update button by mouse, you get this in the browser (button-down-left)

javascript: nm_atualiza(ā€˜alterarā€™);return false;

we are so close jsb :slight_smile:

jscodejsb.jpg

jsb, here is what Iā€™m stuck in right now, i tried also to add the method and enable those fields onBeforeUpdate using the same way but didnā€™t work, it is keep sending the values as 0 to DB

Sorry, it was late at night.

instead of: document.F1[ā€˜id_sc_field_gsa_ā€™+i].disabled = false;

it should be: document.F1[ā€˜id_sc_field_ds_ā€™+i].disabled = false;

This code is only for {ds}, you have to add a line accordingly for every other select field of the row.

jsb

Your new nikename: LIFE SAVER

LIFE SAVER

hi, sorry to open this thread again, just a small Q for jsbinca dude:

does this sc_ajax_javascript thing works on sc8? i have one to disable the form field onLoad record, doing exactly as it was in sc7 but doesnā€™t work in sc8ā€¦ in fact, i have 2 sc_ajax_javascript that makes the fields of the multiple records form 1-change color, 2- disable them in case one of them has the value== ā€œ0ā€ but only first row of the form is affectedā€¦ loading with correct colorā€¦ disable okā€¦ other rows all doesnā€™t affect! what could be wrong!? i have the row_cnt field as we did earlier in SC7

okay, investigating this further, seems sc_ajax_javascript thing works onLoadRecord of my multiple-records form but for some reason it does work for one field and doesnā€™t work for the other!!

this:

If({ds} == ā€˜0ā€™)
{
sc_ajax_javascript(ā€˜js_fields_enableā€™,array({row_cnt}));
}

but this:

If({dx} == ā€˜0ā€™)
{
sc_ajax_javascript(ā€˜js_field_du_color_redā€™,array({row_cnt}));
}

doesnā€™t work! doesnā€™t make sense,
the first one works ok if the second is not in the same event (onLoadRecord)
if i put the second one only, doesnā€™t work at all!
if put both on same event (onLoadRecord) - first work fine but disables the first row only as it matches the criteria (ds=0 then disable the row firleds) and then stopsā€¦ doesnā€™t apply for the other records
the last field of the record is {dx} if is 0 then stops even the first criteriaā€¦ if it is dx=1 then the first criteria is applied until the seond row which has dx=0

hope i could explain itā€¦ i did change and double checked everythingā€¦ nothing seems wrong or different that the SC7 versionā€¦

any hint?

this is really driving me crazyā€¦ the js_method parameter (row_nr) sometimes i click on the js_method to check the code but shows no row_nr paramerter, click again or refresh or logout and login, it shows the row_nr there but doesnā€™t work throughā€¦ only for this stupid fieldā€¦ removed the method and re-created many times, no use, also created new one with other name and called within onLoadRecord, no use grrrrrrrr is it a bug? iā€™m using sc8ā€¦09 of the 9/19/2014

Even if it seems to work (partially), a javascript call is not supposed to work in the onLoadRecord event (see Events x Applications in the docu).
Whatever you want to accomplish, you have to think of a different approach.

jsb

hi jsb,

i have 3 fields, if field1 == 0 i have the this:

sc_ajax_javascript(ā€˜js_field_field1_color_redā€™,array({ row_cnt}));

and if field2 == 0 again
sc_ajax_javascript(ā€˜js_field_field2_color_redā€™,array({ row_cnt}));

these works fine, but the last one doesnā€™t work, even it is exactly as the obove fields, nothing changed
i checked the documentation, the sc_ajax_javascript doesnā€™t they say do not work onLoardRecord but it works for 2 fields!! i checked for test another field and again it is workingā€¦ only one field doesnā€™t, that is strange

also in SC7 was working fine, doesnā€™t say in documentation it must work, but it works normally even the 3 fields though, you gave me this way to color and disable the fields as when loading the multiple records form when we put the row_cnt virtual field and counter =1 in the scriptinitā€¦ hope you remember

any hint or alternative way to solve this with SC8 is highly appreciatedā€¦ Iā€™m yet trying to about to become crazy, just wanna know why

Mike

Hi,
thatā€™s really strange. I canā€™t tell you why it works on all fields but one. There must be something different with this field then.
I know I suggested this solution knowing that the macro wasnā€™t supposed to work, but as you experienced as well, it does in SC7.
I donā€™t use SC8 for production, just for testing/playing aroundā€¦still too much trouble.

jsb

boss, since 8AM this morning until now it is 11PM im stuck into this:

  • changed the xampp to have php 5.4 instead of 5.3
  • imported the db and changed its value like thousand times
  • change the db field about million times
  • changed and removed the field, db table type myisam and innodb (even donā€™t know what is the best)
  • tried differnet sc theme
  • made like break point, changed each single step aloneā€¦ once come to this field/js method all stops
  • updated sc manually many times and one rolled back to previous sc8 version .008 no use

and a lot of stuff, just to know what is the issue why this is happeningā€¦

then wen i read your last reply, i was a minute away from giving up and abandon sc8 forever and go to sc7 and sacrifice mobile support, because i am really getting crazy for such tiny stuff which doesnā€™t make sense and waste time

then guess what? finally decided to change the method name it was ā€œjs_field4_red_bkgā€ made it ā€œjs_field4redā€ and it works!!! this is not funny! because the other method is ā€œjs_field1_white_bkgā€ and works fine!! and with same name ā€œjs_field4_red_bkgā€ works ok on SC7

grrrrrr strange stuff netmake really strange

appreciated your support and care jsb, i really do, always

Glad you got it working. Yeah, sometimes it kinda weird and those machines seem to develop a live of their own. :slight_smile:

jsb

hmmmm on the other hand, netmake should get a medal, while searching for workarounds to adjust their stuff, we or I usually learn tons of other thingsā€¦ looking at the half full looool

cheers