Start a new topic

How to restrict number input to integers and a certain range?

I have a number text box (NexNumber) on a page. In the NextionEditor 'lenth' is set to '6' so that the max nummer you should be able to use is "999999". The standard built-in numeric keyboard is enabled for input (vscope=global, key=numeric keyboard/keybdB).


1) The standard keyboard seems not to pay attention to the max lenth set to 6 in the number text box. You can input longer numbers. How can I change that?


2) You should only be able to input positive integer values. Therefore I would like to hide the . and - button on the keyboard. Or is there another way to achieve input of positive integers only?


3) Say I would like to restrict input to positive integers in a range of 200.000 to 500.000 only. How can I do that?




The keyboards are examples you can unlock and edit once in your HMI

Starting a new project will copy from the original file into your HMI, starting fresh

But, from the HMI point of view there are three such pages using the .key attribute

 - so edits to the keypad would need to apply across all editable numbers in your HMI.


1) In the preinitialize Event of page keybdB

change line 6 to

    inputlenth.val=p[loadpageid.val].b[loadcmpid.val].lenth

2) Delete b99 and b10

    or resize b200 to cover b99 and resize b210 to b10

       and bring the keypad bottom up - adjust and center

3) add a msg.txt Text Component to warn user

    in the b210 release event encapsulate with nested ifs

    cov input.txt,temp.val,0

    if(temp.val<=500000)

    {

       if(temp.val>=200000)

       {

          if(p[loadpageid.val].b[loadcmpid.val].type==54)

         {

           cov input.txt,p[loadpageid.val].b[loadcmpid.val].val,0

         }else

        {

           p[loadpageid.val].b[loadcmpid.val].txt=input.txt

        }

        page loadpageid.val

       }else

       {

          msg.txt="Too Low: x < 200,000"

       }

    }else

   {

      msg.txt="Too High: x > 500,000"

}


Or one could examine the code for the keypad and build their own custom pad to suit their needs, which is more along the lines of what I would probably do.

Thank you very much for the quick and indepth answer! That was exactly the thing I was looking for!

Instead of deleting b99 and b10, I simply hide them for number text boxes with with type==54.

 

if(p[loadpageid.val].b[loadcmpid.val].type==54)
{
  vis b99,0
  vis b10,0
  cov p[loadpageid.val].b[loadcmpid.val].val,input.txt,0
  inputlenth.val=p[loadpageid.val].b[loadcmpid.val].lenth
}else
{
  vis b99,1
  vis b10,1
  input.txt=p[loadpageid.val].b[loadcmpid.val].txt
  inputlenth.val=p[loadpageid.val].b[loadcmpid.val].txt_maxl
  if(p[loadpageid.val].b[loadcmpid.val].type==116)
  {
  show.pw=p[loadpageid.val].b[loadcmpid.val].pw
  }
}
show.txt=input.txt

 

 

Login or Signup to post a comment