Page 1 of 1

allow numbers only in a field

Posted: 2021-11-08 07:48
by amyat
what i need to change my code
please help me
i'm trying

in the hooks/footer-extras.php file:

Code: Select all

<script>
$j(function(){
    AppGini.numericOnly = function(fieldname){
        setInterval(function(){
            var field = $j('#' + fieldname), val = field.val();
            if(val == parseFloat(val)) return;
            val = parseFloat(val.replace(/[^\d.-]/g,''));
            if(isNaN(val)){ field.val(''); return; }
            field.val(val);
        }, 1000);
    };
})
</script>
<div class="navbar navbar-default navbar-fixed-bottom">

		<nav class="" role="navigation">
					<p class="navbar-text"><small>
						Developed by 
					</small></p>

				</nav>
				
</div>
in the hooks/invoices-dv.js file:

Code: Select all

$j(function(){
    AppGini.numericOnly('opd_fee');
    AppGini.numericOnly('rbs_fee');
})
console
Uncaught TypeError: AppGini.numericOnly is not a function

source link https://bigprof.com/blog/appgini/custom ... n-a-field/
it is not working to me , help me please

Re: allow numbers only in a field

Posted: 2021-11-08 14:18
by zibrahim
Hi Amyat,
instead of putting the given codes in hooks/footer-extras.php,
put it in hooks/header-extras.php
i think that the function need to be loaded first before it is being called.

Stay safe.

Re: allow numbers only in a field

Posted: 2021-11-08 21:54
by pbottcher
Hi,

as an alternativ solution you could change the type of the input field to number and add even some other information like min/max/step...