Getting Data In

Validate filter value and show error message if value is invalid

sachinbansal
New Member

Hi,

I want to validate the data i enter in data input filter and also want to show error message if user does not enter valid data. Suppose if the input filter value is supposed to be an integer and the user enters a string then I would like show some message indicating to user that you have entered invalid value.

Thanks.

Regards,
Sachin Bansal

0 Karma
1 Solution

vnravikumar
Champion

Hi

Try this, I had validated with javascript

<form script="validation.js">
  <label>validation</label>
  <fieldset submitButton="true">
    <input type="text" token="integer" id="integer">
      <label>Integer</label>
    </input>
    <input type="text" depends="$hide$" token="show"></input>
  </fieldset>
  <row depends="$form.show$" rejects="$hide$">
    <panel>
      <html>
        <style>
          #error{
          color: red;
          }
        </style>
        <div id="error">

        </div>
      </html>
    </panel>
  </row>
</form>

javascript

require([
"jquery", 
"splunkjs/mvc", 
"splunkjs/mvc/simplexml/ready!"], function($, mvc) {
     var tokens = mvc.Components.get("default");
    $("#submit button").click(function(){
          var tokenValue = tokens.get("integer");
            if (isNaN(tokenValue) || tokenValue < 1) {

                $( "#error" ).text( "Input not valid");
                tokens.set("form.show",true);

              } else{

                  tokens.unset("form.show");
                  $( "#error" ).text("");

              }
    });
});

Updated:

 <form>
   <label>textbox</label>
   <fieldset submitButton="true" autoRun="false">
     <input type="text" token="number" searchWhenChanged="false">
       <label>Enter Integer</label>
       <change>
         <condition match="match(value, &quot;^[0-9]+$&quot;)">
           <unset token="show"></unset>
         </condition>
         <condition match="value== &quot;&quot;">
           <unset token="show"></unset>
         </condition>
         <condition>
           <set token="show"></set>
         </condition>
       </change>
       <initialValue></initialValue>
     </input>
   </fieldset>
   <row depends="$show$">
     <panel>
       <html>
          <style>
            #error{
            color: red;
            }
          </style>
          <div id="error">
           Invalid Input
          </div>
        </html>
     </panel>
   </row>
 </form>

View solution in original post

vnravikumar
Champion

Hi

Try this, I had validated with javascript

<form script="validation.js">
  <label>validation</label>
  <fieldset submitButton="true">
    <input type="text" token="integer" id="integer">
      <label>Integer</label>
    </input>
    <input type="text" depends="$hide$" token="show"></input>
  </fieldset>
  <row depends="$form.show$" rejects="$hide$">
    <panel>
      <html>
        <style>
          #error{
          color: red;
          }
        </style>
        <div id="error">

        </div>
      </html>
    </panel>
  </row>
</form>

javascript

require([
"jquery", 
"splunkjs/mvc", 
"splunkjs/mvc/simplexml/ready!"], function($, mvc) {
     var tokens = mvc.Components.get("default");
    $("#submit button").click(function(){
          var tokenValue = tokens.get("integer");
            if (isNaN(tokenValue) || tokenValue < 1) {

                $( "#error" ).text( "Input not valid");
                tokens.set("form.show",true);

              } else{

                  tokens.unset("form.show");
                  $( "#error" ).text("");

              }
    });
});

Updated:

 <form>
   <label>textbox</label>
   <fieldset submitButton="true" autoRun="false">
     <input type="text" token="number" searchWhenChanged="false">
       <label>Enter Integer</label>
       <change>
         <condition match="match(value, &quot;^[0-9]+$&quot;)">
           <unset token="show"></unset>
         </condition>
         <condition match="value== &quot;&quot;">
           <unset token="show"></unset>
         </condition>
         <condition>
           <set token="show"></set>
         </condition>
       </change>
       <initialValue></initialValue>
     </input>
   </fieldset>
   <row depends="$show$">
     <panel>
       <html>
          <style>
            #error{
            color: red;
            }
          </style>
          <div id="error">
           Invalid Input
          </div>
        </html>
     </panel>
   </row>
 </form>

sachinbansal
New Member

hi @vnravikumar - Thanks for your answer. But is there any way i can do it without .js file. I do not have admin access to search head and indexer to upload a js file.

0 Karma

vnravikumar
Champion

Hi

Try this

<form>
  <label>textbox</label>
  <fieldset submitButton="true" autoRun="false">
    <input type="text" token="number" searchWhenChanged="false">
      <label>Enter Integer</label>
      <change>
        <condition match="match(value, &quot;^[0-9]+$&quot;)">
          <unset token="show"></unset>
        </condition>
        <condition match="value== &quot;&quot;">
          <unset token="show"></unset>
        </condition>
        <condition>
          <set token="show"></set>
        </condition>
      </change>
      <initialValue></initialValue>
    </input>
  </fieldset>
  <row depends="$show$">
    <panel>
      <html>
         <style>
           #error{
           color: red;
           }
         </style>
         <div id="error">
          Invalid Input
         </div>
       </html>
    </panel>
  </row>
</form>
0 Karma

sachinbansal
New Member

hi @vnravikumar - it worked. Thanks a lot man.
Cheers.

0 Karma

vnravikumar
Champion

Please accept the answer.

somesoni2
Revered Legend
0 Karma

sachinbansal
New Member

Solution provided in that link is not meeting my requirement. I want to validate the data type of input value we enter in text field filter and also want to show message if user enter invalid value.

0 Karma
Get Updates on the Splunk Community!

Index This | What is broken 80% of the time by February?

December 2025 Edition   Hayyy Splunk Education Enthusiasts and the Eternally Curious!    We’re back with this ...

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...

Splunk MCP & Agentic AI: Machine Data Without Limits

Discover how the Splunk Model Context Protocol (MCP) Server can revolutionize the way your organization uses ...