Hi,
We want to create a dashboard with Dynamic inputs. Like we will provide a dropbox with SourceType. Depending upon the value of Source type different input text boxes should be provided so that user can enter fields and search results will be provided.
Different input fields dynamically appear on Dashboard depending on the source type.
Thanks,
Prashant
Sorry , Not sure why my answer got cut off.
Try replacing the first input section with the following:
<input type="dropdown" token="Sourcetype">
<label>Sourcetype</label>
<fieldForLabel>sourcetype</fieldForLabel>
<fieldForValue>sourcetype</fieldForValue>
<search>
<query>| metadata type=sourcetypes index=* OR index=_*| fields sourcetype</query>
</search>
</input>
Try replacing you first section with the following:
<input type="dropdown" token="Sourcetype">
<label>Sourcetype</label>
<fieldForLabel>sourcetype</fieldForLabel>
<fieldForValue>sourcetype</fieldForValue>
<search>
<query>| metadata type=sourcetypes index=* OR index=_*
| fields sourcetype
@praspai, just to clarify why you need different text boxes? Instead of that you could provide same text box and control the searches with tokens which has dynamic values based on the user input. If you want different labels (for better user experience) for the text box based on the sourcetype, we could do it using token as well. Lets know if it works
<form>
<label>test</label>
<fieldset submitButton="false" autoRun="false">
<input type="dropdown" token="Sourcetype">
<label>Sourcetype</label>
<choice value="splunkd">splunkd</choice>
<choice value="kvstore">kvstore</choice>
<default>splunkd</default>
</input>
<input type="text" token="txtToken" searchWhenChanged="true">
<label>Enter value based on "$Sourcetype$"</label>
<default>*</default>
<initialValue>*</initialValue>
</input>
</fieldset>
<row>
<panel>
<table>
<search>
<query>index=_internal sourcetype=$Sourcetype$ "$txtToken$" |stats count</query>
<earliest>-15m</earliest>
<latest>now</latest>
</search>
<option name="drilldown">none</option>
<option name="refresh.display">progressbar</option>
</table>
</panel>
</row>
</form>
Hi @renjith.nair ,
Thanks for your response.
We have different attributes for each source type and provide search on those attributes rather free search on raw data.
Say we have a SourceType as Order. We have different attributes on Order like OrderNumber, Customer ID, Item Number, Item Type. We want to provide search on these attributes. so want to provide different input boxes for these attributes.
Another source type is Invoice which have different attributes than Order. so inputs on form should dynamically changed as per source type.
Hope I am able to explain it.
Hi @praspai ,
Have u got any soln for this kind of problem?
@praspai,
If you have defined set of sourcetypes, you could use event handler to set token. Try the below dashboard example and see if it works for you.
<form>
<label>test</label>
<fieldset submitButton="false" autoRun="false">
<input type="dropdown" token="Sourcetype">
<label>Sourcetype</label>
<choice value="order">order</choice>
<choice value="invoice">invoice</choice>
<default>order</default>
<change>
<condition value="order">
<set token="show_order">true</set>
<unset token="show_invoice"></unset>
</condition>
<condition value="invoice">
<set token="show_invoice">true</set>
<unset token="show_order"></unset>
</condition>
</change>
<initialValue>order</initialValue>
</input>
<input type="text" token="field1" depends="$show_order$">
<label>OrderNumber</label>
</input>
<input type="text" token="field2" depends="$show_order$">
<label>Customer ID</label>
</input>
<input type="text" token="field3" depends="$show_order$">
<label>Item Number</label>
</input>
<input type="text" token="field4" depends="$show_order$">
<label>Item Type</label>
</input>
<input type="text" token="field5" depends="$show_invoice$">
<label>Invoice</label>
</input>
<input type="text" token="field6" depends="$show_invoice$">
<label>Customer Id</label>
</input>
<input type="text" token="field7" depends="$show_invoice$">
<label>Invoice Number</label>
</input>
<input type="text" token="field8" depends="$show_invoice$">
<label>Invoice Type</label>
</input>
</fieldset>
</form>
Thanks @renjith.nair ...
I have created a lookup table which maintains the SourceType and attributes .
Can I create these text fields dynamically for each attribute for source type ?
Best Regards,
Prashant
Hi Prashant,
As far as I know, you have to manually create the attributes if its static and then use the tokens to disable/enable them based on the selection.
Hi @renjith.nair,
Do you think we can script it in Javascript ?
Best Regards