Live Number (text) Field

When the database only accept numbers it is important to mark a live field as "number" to reduce MySQL errors while the user is typing, and even on copy paste to prevent submitting unwanted characters.

Just as the live text field we will use the same parameters, but the inputType will be "number" and it is important to add a few attributes, like step and min. Step allows decimals, in the following example 2 decimals, one decimal at a time. 

For Decimals

array_push($td_fields,[
   'type'=>'live',
   'inputType' => 'number',
   'col'=>'balance',
   'privilege'=> 2, //optional, 4 will show the field only to High and Admin privileges, default is 1
   'class'=>'',   //optional, class name selector default: none (empty)
   'attributes'=>'min="0" step=".01"'  //optional
]);

 

For Integers

For integers use step=1 and validate the value on the server. Browser constraints do not replace server validation.


array_push($td_fields,[
   'type'=>'live',
   'inputType' => 'number',
   'col'=>'balance',
   'privilege'=> 2, //optional, 4 will show the field only to High and Admin privileges, default is 1
   'class'=>'',   //optional, class name selector default: none (empty)
   'attributes'=>'min="0" step="1"'  //optional
]);