Is it possible to restrict number of digit of integer field?

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
shkdxb
Veteran Member
Posts: 40
Joined: 2013-06-28 18:18

Is it possible to restrict number of digit of integer field?

Post by shkdxb » 2015-08-29 03:39

I wanted to restrict input to integer field to 8 digits only. if user enters less than 8 digits, i need a pop up saying an error message. Is it possible with Appgini?. My version is 5.30 rev 628.

any help appreciated

User avatar
a.gneady
Site Admin
Posts: 1281
Joined: 2012-09-27 14:46
Contact:

Re: Is it possible to restrict number of digit of integer field?

Post by a.gneady » 2015-08-30 15:40

You can do this by adding a javascript validation rule to the detail view. In the 'hooks' folder, create a file named 'tablename-dv.js' if it's not already there (where tablename is the name of the concerned table), and add your validation code inside it. Here is an example:

Code: Select all

$j('#update, #insert').click(function(){
	if($j('#fieldname').val().length != 8){
		modal_window({
			message: '<div class="alert alert-danger">Fieldname must be 8 digits long.</div>',
			title: "Error in fieldname",
			close: function(){
				$j('#fieldname').focus();
				$j('#fieldname').parents('.form-group').addClass('has-error');
			}
		});
		return false;
	};

	return true;
});
Replace 'fieldname' in the above code with the actual field name.
:idea: AppGini plugins to add more power to your apps:
  • DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
  • Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
  • Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.

shkdxb
Veteran Member
Posts: 40
Joined: 2013-06-28 18:18

Re: Is it possible to restrict number of digit of integer field?

Post by shkdxb » 2015-09-01 17:12

Thanks ahmed
I found the following example under Magic files in Online help, which solved my problem

Code: Select all

document.observe('dom:loaded', function() { 
    $('score').observe('change', function() {
        if(isNaN($F('score')) || $F('score') > 100 || $F('score') < 0){
            alert('Score must be between 0 and 100!');
            $('score').focus();
        }
    });
});

Post Reply