Hi All,
I have a form with two text inputs.
One should validate and allow users to enter alphanumeric and few specific special characters as in the below JS code.
The other should validate whether the user entered is valid IPaddress or not.
I have written the below validation.js code and deployed it to appserver/static and modified the xml code of form to include "id" field as I have found in Splunk docs.
I have restarted my Splunk environment and tried _bump. But there's no validation happening with inputs.
Is it not invoking the JS script at all? Is something wrong with the way I have defined the JS and xml?
<form script="validation.js">
<label>Validation</label>
<fieldset submitButton="true" autoRun="false">
<input type="text" token="URLs" id="URLs_only">
<label>Enter URL</label>
</input>
<input type="text" token="IPs" id="IPs_only">>
<label>Enter IP</label>
</input>
</fieldset>
<row>
<panel>
<table>
<search>
<query>| makeresults
| eval Text="$URLs$, Text1="$IPs$
| table Text Text1</query>
<sampleRatio>1</sampleRatio>
</search>
<option name="count">20</option>
<option name="dataOverlayMode">none</option>
<option name="drilldown">cell</option>
<option name="percentagesRow">false</option>
<option name="rowNumbers">false</option>
<option name="totalsRow">false</option>
<option name="wrap">true</option>
</table>
</panel>
</row>
</form>
require(["underscore", "jquery", "splunkjs/mvc", "splunkjs/mvc/simplexml", "splunkjs/mvc/simplexml/ready!",
"splunkjs/mvc/utils", "splunkjs/mvc/tokenutils" ], function(_, $, mvc, utils, TokenUtils) {
$('#URLs_only').on("change:url", function() {
var tokens = mvc.Components.get("default");
var urlvalue = tokens.get("URLs");
if( /[^a-zA-Z0-9\.\,\:\-\/]/.test( urlvalue ) ) {
console.log(urlvalue);
alert('Input is not valid for URL');
tokens.unset("URLs");
return false;
}
return true;
})
$('#IPs_only').on("change:ipadr", function() {
var tokens = mvc.Components.get("default");
var ipvalue = tokens.get("IPs");
if(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test( ipvalue ) ) {
return true;
}
else{
console.log(ipvalue);
alert('Input is not valid for IpAddress');
tokens.unset("IPs");
return false; }
})
});
Thanks all for your help in advance.
... View more