Announcement

Collapse
No announcement yet.

Changing color of form fields dynamically

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

  • Changing color of form fields dynamically

    Hello, I want to change the background color of a form field dynamically. How can I do this???

  • #2
    Only by using javascript. See: http://scriptcase.aducom.com/cms/e10....php?0.cat.6.7
    Albert Drent
    aducom software netherlands
    scriptcase partner, reseller, support and (turn-key) development
    www.scriptcase.eu / www.scriptcase.nl

    Comment


    • #3
      Thank you Albert for your answer,

      but it does not work for me. There is no change of the background color visible.

      Comment


      • #4
        I discover that the described solution works with control apps but not with form apps. In form apps nothing happened. Is there any solution.

        Best regards.
        HANS

        Comment


        • #5
          Why dont you use a css with a different background color for that form?

          Comment


          • #6
            Hello rr,

            thank you for your answer. I want to change the background color of a field depending on the the state of variable.

            Best regards
            Hans.

            Comment


            • #7
              Yes, but the answer is to invoke some javascript. You can use jquery for that:
              Code:
               $(document).ready(function() {     $('input:text').focus(     function(){         $(this).css({'background-color' : '#FFEEE'});     });      $('input:text').blur(     function(){         $(this).css({'background-color' : '#DFD8D1'});     }); });
              This applies to all formfields, but you can find out the fieldname technically and apply the correct code. There's a sc macro to call a javascript routine.
              Last edited by aducom; 11-10-2015, 04:55 AM.
              Albert Drent
              aducom software netherlands
              scriptcase partner, reseller, support and (turn-key) development
              www.scriptcase.eu / www.scriptcase.nl

              Comment


              • #8
                Sorry but inserting code doesn't work on this forum too.
                Albert Drent
                aducom software netherlands
                scriptcase partner, reseller, support and (turn-key) development
                www.scriptcase.eu / www.scriptcase.nl

                Comment


                • #9
                  Hello Albert,

                  I have not been busy by myself with jQuery. So I can not read the malformatted code snippet. Can you write it as normal text not as code???

                  Thank you
                  Hans.

                  Comment


                  • #10
                    Why did Javascript only work correctly in blank or control forms?

                    Comment


                    • #11
                      Hi everyone,
                      Been messing around with lots of forms lately. Of course, I hit this age old problem of no built-in way to change a field color on a form (verses the nice macro for the grid).

                      I did start using this solution below - but be aware I only use it when I first load the form up.... using the onLoad event. So it only takes effect on that load. Any saves later (updates) do not show up as changes to background colors. You must reload the form to do that (or use a javascript solution per some of the forum posts advise). Loading the form is sufficient for my application and a lot simpler for me.

                      Note that it does not really turn the field background-color - it works using a CSS class that appears to be placed by SC for every form field - seems to work on all types of fields so far like dates, text, selectors... It actually turns a larger box surrounding the label and the value itself. It actually works better for me that way, than just messing with the value box itself. I Iike it.


                      So a form with a field TestFieldONE will have a CSS class of .css_testfieldone_line - note the lowercase.

                      Here is an example of my tests for fields values and colorization of the 2 fields ProgStartDate and PartType. Note how I am changing several fields on the first test, for business logic reasons.


                      if ( ({ProgStartDate} == "") OR ({ProgStartDate} == "0000-00-00") OR ({ProgStartDate} == "null") OR ({ProgStartDate} == "NULL") )
                      {
                      echo "<STYLE>
                      .css_progstartdate_line {
                      background-color: yellow;
                      }

                      .css_age_line {
                      background-color: yellow;
                      }
                      </STYLE>";
                      }

                      if ( ({PartType} == "") )
                      {
                      echo "<STYLE>
                      .css_parttype_line {
                      background-color: yellow;
                      }
                      </STYLE>";
                      }


                      I attached an screen grab of part of a form.

                      BTW these forms have a lot of fields , so I have used this with lots of business logic... so far so good.

                      Hope that helps somebody in the future
                      Peace,
                      Jamie

                      Comment

                      Working...
                      X