Insert full name into a textbox for table's detail view!

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
Gerud Mani
Posts: 9
Joined: 2016-08-22 04:18

Insert full name into a textbox for table's detail view!

Post by Gerud Mani » 2020-02-21 06:33

How can I have 'Full Name' ($memberInfo['custom'][0]) inserted into a text box once user loads the detailed view of a table? I added that to (_before_insert) function but it doesn't actually display it until user clicks save. I think it should be added to (_init) or (_dv) function but not sure how..
It would be great if the function can check if field is empty before inserting the 'Full Name' so it won't insert it if it has data.

Appreciate your help with that

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

Re: Insert full name into a textbox for table's detail view!

Post by jsetzer » 2020-02-21 07:44

Hi,
it's a bit complicated because in _dv hook you don't have any $data-array for populating intitial values. You can try this in your hook-file. Replace TABLENAME by your table name.

Code: Select all

// file: hooks/TABLENAME.php
// ...
function TABLENAME_dv($selectedID, $memberInfo, &$html, &$args) {
  if (!$selectedID) {
    $fieldname = "label"; // <-- your fieldname here
    $html .= '<script>$j(function(){$j("#'.$fieldname.'").val("'.$memberInfo["custom"][0].'");});</script>';
  }
}
// ...
chrome_3dyxCgPt9R.png
chrome_3dyxCgPt9R.png (8.38 KiB) Viewed 4521 times
chrome_WepqOIpAbw.png
chrome_WepqOIpAbw.png (10.04 KiB) Viewed 4521 times

Kind regards,
Jan
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

Gerud Mani
Posts: 9
Joined: 2016-08-22 04:18

Re: Insert full name into a textbox for table's detail view!

Post by Gerud Mani » 2020-02-21 09:31

Thank you very much Jan. That worked perfectly!

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

Re: Insert full name into a textbox for table's detail view!

Post by jsetzer » 2020-02-21 11:43

Great, I'm glad to hear that it works!
Best,
Jan
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

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

Re: Insert full name into a textbox for table's detail view!

Post by jsetzer » 2020-02-22 08:44

Good morning,

if anyone else is interested in this: I have written a step-by-step tutorial on changing default values in insert-mode.

There are two parts:
I look forward to your feedback.

Regards,
Jan

Code

Code: Select all

function contacts_dv($selectedID, $memberInfo, &$html, &$args)
{
  if (!$selectedID) {
    $init_data = [
      "label" => $memberInfo["custom"][0],
      "last_name" => "Io",
      "first_name" => "Europa",
      "middle_names" => "Ganymed",
      "memberID" => $memberInfo["username"]
    ];
    $html .= '<script>' . implode("\r\n", array_map(function($fieldname, $value) { return "jQuery('#{$fieldname}').val('{$value}');"; }, array_keys($init_data), $init_data )) . '</script>';
  }
}
Result
chrome_MlXKXRJbNm.png
chrome_MlXKXRJbNm.png (24.14 KiB) Viewed 4459 times
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

Post Reply