Splunk ITSI

change the color of a text input border

coreyCLI
Path Finder

I want to be able to change the color of a text input border when you focus on the input box.  I want to change the blue border to red when the field is empty.  I have the javascript logic but not the css that would change the blue border. 

coreyCLI_0-1729525829819.png

Here is the css I have so far but all it does is put a border around the whole input panel, not just the text box.

.required button{
    border: 2px solid #f6685e !important;
}

 

coreyCLI_0-1729526466949.png

 

 

Labels (1)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Assuming you have given your text input field an id of "required"

          #required .splunk-textinput {
            border: 2px solid #f6685e !important;
          }
0 Karma

marnall
Motivator

Are you able to use the ID of the div containing the text input to apply the border style?

E.g. my test input has id=input1_11212 , so using:

#input1_11212 {
    border: 2px solid #f6685e !important;
}

Results in a red border:

marnall_0-1729537257069.png

 

0 Karma

coreyCLI
Path Finder

I am using Splunk version 9.3.1 and I get the same results using your example.  A red border around the entire panel and not just the text box itself.

 

coreyCLI_0-1729602364909.png

 

 

 

0 Karma

marnall
Motivator

My test machine is also on Splunk version 9.3.1.

Could you post sanitized snippets of your JS or dashboard source code? It's hard to see where the issue lies without seeing the full picture.

0 Karma

coreyCLI
Path Finder

Here is the JS.  I gave the input id="user_name".

require([
    "splunkjs/mvc",
    "splunkjs/mvc/simplexml/ready!"
], function (mvc) {

    // get default token model
    var tokens = mvc.Components.getInstance("default");
    var user_name = document.getElementById("user_name");

    // Set required style if init value is undefined to channel
    if (tokens.get("user_name") === 'Enter a User') {
        user_name.classList.add("required");
    }


    // Dropdown change on channel 
    tokens.on("change:user_name", function (model, value) {
        if (value === 'Enter a User') {
            user_name.classList.add("required");
        } else {
            user_name.classList.remove("required");
        }
    });

});

 

Here is the CSS again just to capture it all in the same reply.

.required button{
    border: 2px solid #f6685e !important;
}

 

I use this code (more or less) on other dashboards to perform the same "required" function on other inputs like drop downs and it works by creating a red outline around the drop down until a choice is made.

coreyCLI_0-1729679262176.png

 

0 Karma
Get Updates on the Splunk Community!

Earn a $35 Gift Card for Answering our Splunk Admins & App Developer Survey

Survey for Splunk Admins and App Developers is open now! | Earn a $35 gift card!      Hello there,  Splunk ...

Continuing Innovation & New Integrations Unlock Full Stack Observability For Your ...

You’ve probably heard the latest about AppDynamics joining the Splunk Observability portfolio, deepening our ...

Monitoring Amazon Elastic Kubernetes Service (EKS)

As we’ve seen, integrating Kubernetes environments with Splunk Observability Cloud is a quick and easy way to ...