Hi,
I am looking for a sample to set a initial value dynamically using eval or JavaScript.
e.g. set "Monday" or "Tuesday" as a initial value when a form is opened.
I have this very simple form like this:
<form>
<label>sample</label>
<fieldset submitButton="false">
<input type="text" token="a">
<label>Today</label>
<initialValue></initialValue>
</input>
</fieldset>
</form>
and I want to set a value for depending on a day the form is accessed.
I am looking for a way to do this by eval tag or JavaScript extention, but I have not found any sample for this kind of input value initialization.
Any simple sample would be appreciated!
You can give the input an id in Simple XML, get that input by its id in your js code and set its default
setting. Should look something like this:
...
type="text" token="a" id="textInput">
<label>Today</label>
...
And in js:
...
var textInput = mvc.Components.get("textInput");
textInput.settings.set("default", "some value or dynamic text");
You can do the same with initialValue, though I doubt you really need that. Docs for that are here.
You can give the input an id in Simple XML, get that input by its id in your js code and set its default
setting. Should look something like this:
...
type="text" token="a" id="textInput">
<label>Today</label>
...
And in js:
...
var textInput = mvc.Components.get("textInput");
textInput.settings.set("default", "some value or dynamic text");
You can do the same with initialValue, though I doubt you really need that. Docs for that are here.
Thank you! Now I can start adding some more stuff for text box initialization ...
<form script="sample.js">
<label>sample</label>
<fieldset submitButton="false">
<input type="text" token="token1" id="id1">
<label>Text Input</label>
</input>
</fieldset>
</form>
$ cat sample.js
require(["splunkjs/mvc", "splunkjs/mvc/simplexml/ready!"], function(mvc) {
var date1 = new Date();
var year = date1.getFullYear();
var val1 = mvc.Components.get('id1');
val1.settings.set("default", year);
});
Create a lookup mylookup.csv like below
day_of_w, No
......................
Sunday ,0
Monday ,1
Tuesday ,2
.
.
Saturday,6
|inputlookup mylookup.csv | eval date_wday=strftime(now(),"%w") | eval No=if(date_wday==No,0,No) | sort No | table day_of_w
Thank you for your input, and I understand what you showed. But could this search result be used for setting initial value for input as a text?
You can use a drop down and use
<selectFirstChoice>true</selectFirstChoice>
I'm sure there must be a way to populate text box as well