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!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...