Forum Discussion

team_aras_meupe_com's avatar
2 years ago
Solved

Applying backgroundColor property in a form

Hello, I'm trying to change the background color of a form. It seems simple, but no!!

I have tried several methods but none of them work for me, it does not change the background color of the bodysuit, but rather what is behind it.

With the debugger I have seen that there is the "body" and the "claro" class, but I cannot change the color of "claro", only the body that is behind "claro".


[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:bb63d6ba-a8ed-4391-8162-e2a125229adc:type=javascript&text=var%20cualColor%20%3D%205%3B%20%2F%2F%20Por%20probar%20un%20valor%0Avar%20elementoConClaseClaro%20%3D%20document.querySelector%28%27.claro%27%29%3B%0A%0A%2F%2F%20Verificar%20si%20se%20encontr%C3%B3%20un%20elemento%20con%20la%20clase%20.claro%0Aif%20%28elementoConClaseClaro%29%20%7B%0A%20%20if%20%28cualColor%20%3D%3D%3D%205%29%20%7B%0A%20%20%20%20elementoConClaseClaro.style.backgroundColor%20%3D%20%22red%22%3B%0A%20%20%7D%20else%20if%20%28cualColor%20%3D%3D%3D%2010%29%20%7B%0A%20%20%20%20elementoConClaseClaro.style.backgroundColor%20%3D%20%22blue%22%3B%0A%20%20%7D%0A%7D]

I have tried with:

- var body = document.querySelector('.clear');
- var body = document.body;
- var body = document.getElementById("clear");

and some more, but nothing.

I have noticed that it works, but it changes the color of the background, you can see it by a thin line at the bottom.

Esto veo en el debugger:

Too many thanks!!!

  • asebastian's avatar
    asebastian
    2 years ago

    I was able to set the background color by modifying document.body.style.backgroundColor within an onFormPopulated Form Event. When I was attempting to modify just document.body.bgColor it was being overwritten by the default.css. Directly updating the style in the method code seems to have fixed the issue:

4 Replies

  • asebastian's avatar
    asebastian
    Community Manager

    Hello,

    Have you tried utilizing the background color property on the item form itself? It can be found under the Form Body section of the form editor:

    • team_aras_meupe_com's avatar
      team_aras_meupe_com
      Creator III

      Yes, I know that method, what happens is that when the form is opened, depending on the value of the OF (Manufacturing Order) status, it should take on one color or another. That's why I have to do it by code.

      I have also tried to do it by code from the CSS of the "Form Body" and it works, but I have never tried to mix CSS with AML, I would have to take the value of the State field and depending on what it has, show one color or another.

      That's why I decided to create a method, but I don't know how to take and assign "body.claro" to the variable and use: elementConClaseClara.style.backgroundColor = "red";

      Thank you.

      Greetings.

      • asebastian's avatar
        asebastian
        Community Manager

        I was able to set the background color by modifying document.body.style.backgroundColor within an onFormPopulated Form Event. When I was attempting to modify just document.body.bgColor it was being overwritten by the default.css. Directly updating the style in the method code seems to have fixed the issue: