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
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...