Skip to Content
Author's profile photo Former Member

Changing the Background color in text box using Custom CSS.(With some condition “If-else”)

Hi community,

If You want to use condition formatting in Text Box or wanna change the background/font-color based on different selection then i think it may help you.

Here i put a dimension filter and a text box.

based on dimension filter selection i want to change the background color of the text box.

1st.JPG 

2nd.JPG

3ed.JPG

4th.JPG

5th.JPG

for achieving that things i used a Custom CSS file…..

CSS.JPG

saved that file in my root folder.

then i write some script in dimension filter event “On Apply”……..

Script editor.JPG

so using that script that thing work.

Thanks,

Anshul

Assigned Tags

      5 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Dear Anshul,

      Thanks for that great Idea!

      Additionally, you could build the color definition based on data using the getData() functionality. This would give you less static script.

      br

      Daniel

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Dear Daniel,

      can you please explain bit more then only i can implement on that approach.

      thanks,

      Anshul

      Author's profile photo Former Member
      Former Member

      My case would not be based on City, it would be based on

      Data > 100 --> Red Data > 200 Green ...

      Anyway to shorten your coding, change your CSS:

      Austin: { background: #..... }

      Boston: { background: #..... }

      others: { background: #......}

      And your script:

      var city = ds_1.getFilterExt("CITY")

      if( city != "" ) {

           text_1.setCSSClass( city );

      } else {

           text_1.setCSSClass( "others" );

      }

      no guaranty for the syntax, just freehand coding..

      br

      Daniel

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      thanks Daniel,

      good option.

      regards,

      Anshul

      Author's profile photo Former Member
      Former Member

      Where should I save my .CSS file ? May I know the root folder location ?

      Thanks in advance.