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
If we only want to allow integers step should be equal to 1 and to prevent decimals add the following JS to the attributes: onkeypress="return event.charCode >= 48 && event.charCode <= 57"


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" onkeypress="return event.charCode >= 48 && event.charCode <= 57"'  //optional
]);