Just as the text field we will use the same parameters, but the type 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
addField([ 'type'=>'number', //required 'attributes'=>'min="0" step=".01"', //optional 'name'=>'', //optional (leave empty if you don't want to submit the value) 'value'=>'', //optional (predefined value) 'placeholder'=>'', //optional 'label'=>'Information Text', //required 'id'=>'', //optional (name becomes the id by default) 'style'=>'', //optional 'class'=>'', //optional 'blockClass'=>'', //optional (class for the container) 'blockStyle'=>'', //optional (style for the container) 'dataString'=>'data-test="value"', //optional (full data attribute and value) ]);
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"
addField([ 'type'=>'number', //required 'attributes'=>'min="0" step="1" onkeypress="return event.charCode >= 48 && event.charCode <= 57"', //optional 'name'=>'', //optional (leave empty if you don't want to submit the value) 'value'=>'', //optional (predefined value) 'placeholder'=>'', //optional 'label'=>'Information Text', //required 'id'=>'', //optional (name becomes the id by default) 'style'=>'', //optional 'class'=>'', //optional 'blockClass'=>'', //optional (class for the container) 'blockStyle'=>'', //optional (style for the container) 'dataString'=>'data-test="value"', //optional (full data attribute and value) ]);
Quick Mode:
addField('number:min="0" step=".01"', 'Label', 'DB Column Name','Input Value');