Page 1 of 1

Mandatory field

Posted: 2022-09-14 16:22
by angus
Is there an easy way to make a field mandatory except for the Admin

Re: Mandatory field

Posted: 2022-09-14 16:56
by jsetzer
NOT NULL flag is defined on database level, not on UI level/code level.

Short answer: not possible unless you override validation on client side (javascript) AND modify $data in _before hook on serverside (PHP) for example by replacing NULL by empty string.

Re: Mandatory field

Posted: 2022-09-14 19:22
by angus
thanks Jsetzer, you gave me an idea. I removed the not null from the DB & Appgini.

I then added a const to the /hooks/header-extras.php as wasn't sure how else to get the group ID in the dv file (not perfect but think it will work)

Code: Select all

<script>
const Group = '<?=getLoggedGroupID()?>';
</script>
then I used the custom fault message in the /hooks/dv file

Code: Select all

$j(function(){
				$j('#update, #insert').click(function(){
					
					//Group is defined in headers-extras.php as a const 
					var ChangeG = $j('#Field1').val();
					
					if(ChangeG == '' && Group !== '2')                 
					{
						return show_error('ChangeGrouping', '<strong>Important: The Change Grouping must be entered</strong>');
					}
				});
			})
I have tested this a few times and seems to work ok. posting for anyone else looking for something similar.