Announcement

Collapse
No announcement yet.

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

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

  • #2
    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

    Comment


    • #3
      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?

      Comment


      • #4
        Originally posted by itsme3 View Post
        any hint? or the error location?
        You change the background color for field "yt" and then disable this field?
        Best regards: - Reinhard -

        I use ScriptCase 8 Enterprise Edition, Version 8.(latest)

        Comment


        • #5
          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

          Comment


          • #6
            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

            Comment


            • #7
              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_c nt}));
              }

              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

              Comment


              • #8
                I'm sorry jsb, couldn't get it working 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



                Originally posted by jsbinca View Post
                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_c nt}));
                }

                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

                Comment


                • #9
                  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...amming/methods

                  jsb
                  Attached Files

                  Comment


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

                    Comment


                    • #11
                      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 you can hide it though

                      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!?

                      http://www.scriptcase.net/forum/show...4229#post24229

                      Comment


                      • #12
                        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?

                        Comment

                        Working...
                        X