This is the JS I'm using to check if user ID is 7 digits
require([
"jquery",
"splunkjs/mvc/simplexml/ready!"
], function($,TableView, mvc, DashboardController){
var checkAndSetEvents = function() {
if($("#user_input").length) {
$("#user_input").change(function(event){
if(event.target.value && event.target.value.length > 7) {
$(".btn.btn-primary.submit").removeAttr("disabled");
} else {
$(".btn.btn-primary.submit").attr("disabled", "disabled");
}
});
} else {
setTimeout(checkAndSetEvents, 500);
}
}
checkAndSetEvents();
});
Hi,
to include the script in your dashboard, please check the following:
<form script="myfile.js"> ... </form>
$SPLUNKDIR/etc/apps/<appname>/appserver/static
and the file is in the right placeIf it still doesn't work, maybe you could post your simpleXML and a little more details.
Hope it helps
Oliver
yes I have added my js in $SPLUNKDIR/etc/apps//appserver/static and it is readable, yet its not working.
Add New User
<input type="text" token="user">
<label>Enter User ID</label>
Select Roles
All
<query>| rest /services/authorization/roles splunk_server="local" | fields title | rename title as roles | mvexpand roles | dedup roles | sort + roles</query>
<earliest>-1d@d</earliest>
<latest>now</latest>
roles
roles
<search>
|script add_user "$user$" $roles$
-1d@d
now
</panel>
Its called in the dashboard as below
User check
<input id="user_input" type="text" token="user">
<label>Enter User ID</label>
</input>
.........................
.........................
@DavidHourani : This is my dashboard, I need to enable the submit button only when 7 digits are entered in textbox for user id.
Add New User
<input type="text" token="user">
<label>Enter User Bank ID</label>
</input>
<input type="multiselect" token="roles" searchWhenChanged="false">
<label>Select Roles</label>
<choice value="*">All</choice>
<search>
<query>| rest /services/authorization/roles splunk_server="local" | fields title | rename title as roles | mvexpand roles | dedup roles | sort + roles</query>
<earliest>-1d@d</earliest>
<latest>now</latest>
</search>
<fieldForLabel>roles</fieldForLabel>
<fieldForValue>roles</fieldForValue>
</input>
<panel>
<search>
<query>|script add_user "$user$" $roles$</query>
<earliest>-1d@d</earliest>
<latest>now</latest>
</panel>
Hi @GGrishma,
Could you please share your dashboard ?
Also have a look at some previous answers on how to setup JS on the XML dashboard. Could be a good idea to start with a simple alert before moving to another function :
https://answers.splunk.com/answers/586958/how-do-i-add-javascript-to-a-splunk-dashboard.html
Cheers,
David
I have called the js in my dashboard
@DavidHourani : This is my dashboard, I need to enable the submit button only when 7 digitd are entered in textbox for user id.