allow numbers only in a field

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
amyat
Veteran Member
Posts: 45
Joined: 2020-06-24 20:39

allow numbers only in a field

Post by amyat » 2021-11-08 07:48

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

User avatar
zibrahim
Veteran Member
Posts: 137
Joined: 2020-01-28 18:30
Location: Malaysia

Re: allow numbers only in a field

Post by zibrahim » 2021-11-08 14:18

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.
Zala.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: allow numbers only in a field

Post by pbottcher » 2021-11-08 21:54

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...
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

Post Reply