Dashboards & Visualizations

How to limit number of input values in Text Box input

mbasharat
Contributor

Hi,

I have text box input that I have tweaked for taking multiple values and it works fine. I need to limit number of values that a user can insert. How to do this?

Thanks in-advance!!!! 

Labels (3)
Tags (1)
1 Solution

niketn
Legend

@mbasharat I think the idea is to ensure that original token is not used as is in the final search.

For example

  1. Set token from text box to $tok_input_text$ and then perform validation.
  2. After the validation passes set the token $tok_validated_text$ which should be used by the searches.
  3. This final token should not be set if validation fails.
  4. This should also be unset each time text box input value changes.

I am sure I would have taken care of above steps in the previous example as well. However, if it is not clear refer to a very basic 9 digit validation answer which should explain these steps better: https://community.splunk.com/t5/Developing-for-Splunk-Enterprise/Textbox-Character-limitation/m-p/52...

Do up vote the original answers as well if they help! 🙂

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

View solution in original post

0 Karma

niketn
Legend

@mbasharat what do you mean by limiting the number of values? Are values some type of delimited strings? Or are they based on length?

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

mbasharat
Contributor

Hi @niketn 

It is a text box input on one of my dashboards where user can insert more than on Vulnerability IDs separated/delimited by comma. At the moment, they can insert as many as they want but we need to have this input limited e.g. no more than 10 Vulnerability IDs.

Vulnerability ID is in below format and it is standard:

ABC-2020-1234

When user inputs more than one, it looks like this:

ABC-2020-1234,DEF-2020-1234,GHI-2020-1234 and so on.

If I understand it will need to be character limit to be placed. For example, above three total 41 characters including comma delimiter.

Custom CSS/JS etc. are not the options available or what I am looking for. If an XML code can be done in dashboard, that will be great and lesser maintenance.

Note: I am posted another question referencing one of your solutions in the past for another issue below so if you ca look at this one and guide as well, that will be great. Thanks!!!

https://community.splunk.com/t5/Dashboards-Visualizations/Increasing-size-of-textbox-input/m-p/52040... 

niketn
Legend

@mbasharat I think the idea is to ensure that original token is not used as is in the final search.

For example

  1. Set token from text box to $tok_input_text$ and then perform validation.
  2. After the validation passes set the token $tok_validated_text$ which should be used by the searches.
  3. This final token should not be set if validation fails.
  4. This should also be unset each time text box input value changes.

I am sure I would have taken care of above steps in the previous example as well. However, if it is not clear refer to a very basic 9 digit validation answer which should explain these steps better: https://community.splunk.com/t5/Developing-for-Splunk-Enterprise/Textbox-Character-limitation/m-p/52...

Do up vote the original answers as well if they help! 🙂

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

mbasharat
Contributor

Great. This worked!!! THANK YOU 🙂

0 Karma

niketn
Legend

@mbasharat So you want to restrict only 10 Vulnerability IDs which are comma delimited. Please refer to one of my previous answers of validating only 5 URLs using an independent search to perform complex validations. The solution is purely Simple XML however, you need to change the validation to pattern match for vulnerability and up to 10 comma separated values instead of 5.

https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-a-text-box-using-condition/t...

This should be straightforward conversion, if not let me know!

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

mbasharat
Contributor

Hi @ niketnilay,

I have tweaked and consolidated your provided solution code based on my need and it works perfect to produce validation errors to users.

However, there is one big issue. I am using | search vuln_id IN ($vulnid$) in my search. If a user inserts 11 values instead of limit of 10 in validation check in your solution, validation errors are produced as coded but search still runs for 11 values instead of 10. How to make the search fail unless user inserts 10 values or less?

Thanks and awaiting response.

thambisetty
SplunkTrust
SplunkTrust

you can add simple js to your simple xml.

The below JS has two options, either you can limit characters based on input id or all inputs is commented. 

Only input which has id "user_text_input" in simple xml will be limited to 9 characters.

require(['jquery','splunkjs/mvc','splunkjs/mvc/simplexml/ready!'], function(){
   //Below is based on input ID
   $('#user_text_input').find(':input').attr("maxlength", 9); 
   //Below is for all inputs
   //$('input').attr("maxlength", 9); 
});

simple.xml

<form script="limittextboxchars.js">
  <label>Limit - texbox characters</label>
  <fieldset submitButton="false">
    <input type="text" id="user_text_input" token="field1">
      <label>field1</label>
    </input>
    <input type="text" token="field2">
      <label>field2</label>
    </input>
  </fieldset>
</form>

 

————————————
If this helps, give a like below.

mbasharat
Contributor

Hi @ thambisetty,

Please see my response with additional details to @niketn Thanks in-advance!!!

Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...