Validation property from other input field?

I know there are other threads on this topics but cant seem to find my precise question so fast so here it goes :

I want to use the validation function to use 2 of the users input and check if minimum is bigger than maximum input.
my code :

i_min:{value:0, 
                required:true,
                validate:function(v) {
                    let result = false;
                    let i_max = $("#node-input-i_max");
                    if(v<i_max){result = true;}
                   
                    return result;
                }
            },
            i_max:{value:0}, 

If I fill in a number for i_max manually in the code for example 5 it does the check like I expect it. So this part $("#node-input-i_max") doesnt seem to work. Could somebody direct me to the right syntax to get the input for my i_max value assuming the name is " node-input-i_max "

If you have not already seen it, you should look at the custom property validator in the example here.

Ive seen it and tried various things but cant make up what the syntax says...

$("node-input-i_max").val() for example doesnt work either which is something I thought would hold the value of the input for i_max which the user entered?

Which is maybe the better question here for me. Could someone break down the syntax wrote in the example for me ? Then I could see where my error lies :

 custom: { value:"", validate:function(v) {
      var minimumLength=$("#node-input-minimumLength").length?$("#node-input-minimumLength").val():this.minimumLength;
      return v.length > minimumLength
   } }

I thought so too, but I'm no jQuery expert. Others might be able to help. You could try logging these variables to the console to see what they hold.

ok so it dit work as I expected it... it was the value of the input...
it translated it to text in stead of a number... even though the input explicitely is put as number...

so this fixed it :

i_min:{value:0, 
                required:true,
                validate:function(v) {
                    let result = false;
                    let i_max = $("#node-input-i_max").val();
                    if( parseFloat(v) < parseFloat(i_max) ){result = true;}
                    //alert(v);
                    return result;
                }
            },
            i_max:{value:0,required:true}, 

It's an html thing. The browser has no way to know what you want to do with the input, and at bottom it can only handle text. Converting input to a JavaScript type is up to you.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.