Dashboards & Visualizations

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

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

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

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

Builder

Thank you! I'll be implementing this soon.

0 Karma

Legend

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

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma
Don’t Miss Global Splunk
User Groups Week!

Free LIVE events worldwide 2/8-2/12
Connect, learn, and collect rad prizes
and swag!