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

 

 

Guys thank you for this post, learned a lot reading these commands lines. Nevertheless I'm still stuck on how to send to arduino an updated txt value after pressing the OK (b210) button, from this keyboard.

Right now,  what I did was to declare: get t0.txt at the Touch Release Event (from t0), thus I only receive the updated value after pressing twice the object. Could you please help me? Appreciated.

Honestly

unless there is only one HMI value that changes with the keyboard use

then it is perhaps the wrong logic flow.


To push a value at the MCU without the "when" is to lose the value.

Rather, a simple 0x65 notifies the MCU as to the touch

 - the MCU when ready and prepared should fetch.


Redefine what the actual flow of information should be

 and you have your answer.


From the Debug I noticed the 0x65 returned data, even so not sure how to handle it. From the library (ITEADLIB_Arduino_Nextion-master) point of view, what should I use? Tks.

What you see in Debug, Nextion sends to the MCU.

Iteadlib Arduino Nextion library is setup to trap and handle 0x65 touch events.


Therefore, see examples in the examples folder for pattern of how to setup.


Also see 

https://nextion.itead.cc/forums/topic/basic-framework-sketch-for-arduino/ 

in the new forum, if you can not see this: register here

https://nextion.itead.cc/join/

and login to view

Login or Signup to post a comment