How to set a lookup field default value in the hooks file

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
User avatar
pilandros
Veteran Member
Posts: 93
Joined: 2014-02-13 18:19

How to set a lookup field default value in the hooks file

Post by pilandros » 2015-02-21 17:17

Hi there,
I have this problem. I need to set a default selected value in a lookup field when inserting a new record to a table.

In this particular case I have an attendance table and I need that each student (or member) updates its records by just adding a record into the attendace table. since each student is a member with a user ID, I have a students-table with a field that matches that user ID. So each time a student inserts a record that has a student_id lookup field I need that field to be already defaulted to the userID from the members table (which I know is available via the $memberInfo['username'] array)
So I figured that somehow within the ../hooks/attendace.php file I may do that. But I'm stuck with the jQuery code which obviously I do not dominate.

I already thought of inserting a PHP code in the attendance_after_insert function to do this, but that still does leave my app with a flaw in the displayed lookup value and a funny message saying something like "don't worry it will work after you SUBMIT it"

I saw a sample from ahmad in this forum, which suggeste to place the following code within the ../hooks/filename.php on the header section and use to set the $header variable:
$js_code = '<script>jQuery(function(){' .
'jQuery("form").append(\'<input name="filterer_Reporter" type="hidden">\');' .
'jQuery("input[name=filterer_Reporter]").val("' . $memberInfo['username'] . '");' .
'});</script>';
.. then
$header = '<%%HEADER%%> $js_code';

so by a long-shot guess I developed the following (which did not produce an error but did not work either)
$js_code = '<script>jQuery(function(){' .
'jQuery("select[name=stud_id]").val("' . $sid . '");' .
'});</script>';
.. then
$header = '<%%HEADER%%> $js_code';

any help on this matter will be much appreciated

Post Reply