Page 1 of 1
Insert full name into a textbox for table's detail view!
Posted: 2020-02-21 06:33
by Gerud Mani
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
Re: Insert full name into a textbox for table's detail view!
Posted: 2020-02-21 07:44
by jsetzer
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 (8.38 KiB) Viewed 5239 times

- chrome_WepqOIpAbw.png (10.04 KiB) Viewed 5239 times
Kind regards,
Jan
Re: Insert full name into a textbox for table's detail view!
Posted: 2020-02-21 09:31
by Gerud Mani
Thank you very much Jan. That worked perfectly!
Re: Insert full name into a textbox for table's detail view!
Posted: 2020-02-21 11:43
by jsetzer
Great, I'm glad to hear that it works!
Best,
Jan
Re: Insert full name into a textbox for table's detail view!
Posted: 2020-02-22 08:44
by jsetzer
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 (24.14 KiB) Viewed 5177 times