Skip to Content

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

5 Comments
You must be Logged on to comment or reply to a post.
  • 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

      • 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