Page 1 of 1

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

Posted: 2015-08-29 03:39
by shkdxb
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

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

Posted: 2015-08-30 15:40
by a.gneady
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.

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

Posted: 2015-09-01 17:12
by shkdxb
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();
        }
    });
});