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?
@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).
$('#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
};
});
@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).
$('#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
};
});
Thank you! I'll be implementing this soon.
@thisissplunk, do let us know if you run into any issues!