Dashboards & Visualizations

How do I prevent empty values from being submitted to my KV store on my dashboard?

thisissplunk
Builder

I have an HTML dashboard that lets me submit values to my kv store. How do I check the values for emptiness and then inform the user that the values are empty?

0 Karma
1 Solution

niketn
Legend

@thisissplunk, if your Submit Button has id #submit_btn and your inputs are input1, input2 ... etc., JavaScript similar to the following can be used to access tokens using Splunk's default token model. If any of the required input/s is/are not provided, validation error will be displayed. When there is no validation error, you can submit the data dictiornary to KV Store using REST (PS: only placeholder has been provided in following example).

alt text

 $('#submit_btn').on("click", function() {
    var defaultTokens = mvc.Components.get("default");

    var tokValidation = "";
    var tokValidation = (defaultTokens.get("input1") === undefined || defaultTokens.get("input1") == "" ? tokValidation + "\n" + "\u2022 Please provide input1" : tokValidation );
    var tokValidation = (defaultTokens.get("input2") === undefined || defaultTokens.get("input2") == "" ? tokValidation + "\n" + "\u2022 Please provide input2" : tokValidation );
    var tokValidation = (defaultTokens.get("input3") === undefined || defaultTokens.get("input3") == "" ? tokValidation + "\n" + "\u2022 Please provide input3" : tokValidation );
    var tokValidation = (defaultTokens.get("input4") === undefined || defaultTokens.get("input4") == "" ? tokValidation + "\n" + "\u2022 Please provide input4" : tokValidation );

    if(tokValidation.length>0){
        alert("Required inputs missing. Data will not be submitted to KV Store.\nPlease fix validation errors and submit again:\n" + tokValidation);
        // Required values not provided. Do not submit to KV Store
    }else{
        alert("Details provided submitted to KV Store Successfully!");
        // All inputs provided. Code to submit inputs to KV Store
    };
 });
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

View solution in original post

0 Karma

niketn
Legend

@thisissplunk, if your Submit Button has id #submit_btn and your inputs are input1, input2 ... etc., JavaScript similar to the following can be used to access tokens using Splunk's default token model. If any of the required input/s is/are not provided, validation error will be displayed. When there is no validation error, you can submit the data dictiornary to KV Store using REST (PS: only placeholder has been provided in following example).

alt text

 $('#submit_btn').on("click", function() {
    var defaultTokens = mvc.Components.get("default");

    var tokValidation = "";
    var tokValidation = (defaultTokens.get("input1") === undefined || defaultTokens.get("input1") == "" ? tokValidation + "\n" + "\u2022 Please provide input1" : tokValidation );
    var tokValidation = (defaultTokens.get("input2") === undefined || defaultTokens.get("input2") == "" ? tokValidation + "\n" + "\u2022 Please provide input2" : tokValidation );
    var tokValidation = (defaultTokens.get("input3") === undefined || defaultTokens.get("input3") == "" ? tokValidation + "\n" + "\u2022 Please provide input3" : tokValidation );
    var tokValidation = (defaultTokens.get("input4") === undefined || defaultTokens.get("input4") == "" ? tokValidation + "\n" + "\u2022 Please provide input4" : tokValidation );

    if(tokValidation.length>0){
        alert("Required inputs missing. Data will not be submitted to KV Store.\nPlease fix validation errors and submit again:\n" + tokValidation);
        // Required values not provided. Do not submit to KV Store
    }else{
        alert("Details provided submitted to KV Store Successfully!");
        // All inputs provided. Code to submit inputs to KV Store
    };
 });
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

thisissplunk
Builder

Thank you! I'll be implementing this soon.

0 Karma

niketn
Legend

@thisissplunk, do let us know if you run into any issues!

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma
Get Updates on the Splunk Community!

Index This | Why did the turkey cross the road?

November 2025 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  🚀 Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Feel the Splunk Love: Real Stories from Real Customers

Hello Splunk Community,    What’s the best part of hearing how our customers use Splunk? Easy: the positive ...