Mandatory field

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
angus
Veteran Member
Posts: 128
Joined: 2020-05-28 22:27

Mandatory field

Post by angus » 2022-09-14 16:22

Is there an easy way to make a field mandatory except for the Admin
AppGini 22.13

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Mandatory field

Post by jsetzer » 2022-09-14 16:56

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.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

angus
Veteran Member
Posts: 128
Joined: 2020-05-28 22:27

Re: Mandatory field

Post by angus » 2022-09-14 19:22

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.
AppGini 22.13

Post Reply