insert html elements before a field

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
fgazza
Veteran Member
Posts: 205
Joined: 2019-04-30 17:37

insert html elements before a field

Post by fgazza » 2020-06-06 20:02

Hello everyone!
I would like to insert a custom text before a field. The text should be formatted in html and precede the field label.
I think the solution is to use $html in the hook file's tablename_dv () function but I have no idea how to use it. For example, I would like to display the image mysite / image.jpg before the field label and a paragraph below the image.

Could anyone please tell me how to use the $html parameter?

THANKS!

Fabiano

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 348
Joined: 2018-03-04 09:30
Location: David

Re: insert html elements before a field

Post by D Oliveira » 2020-06-08 11:52

fgazza wrote:
2020-06-06 20:02
Hello everyone!
I would like to insert a custom text before a field. The text should be formatted in html and precede the field label.
I think the solution is to use $html in the hook file's tablename_dv () function but I have no idea how to use it. For example, I would like to display the image mysite / image.jpg before the field label and a paragraph below the image.

Could anyone please tell me how to use the $html parameter?

THANKS!

Fabiano
I might be wrong because I never used html in that function but your can try echo '<p> html code</p>'; or close and re-open the php syntax like this:

Code: Select all


?>

<p>hmtl code</p>

<?php


hope it helps, cheers!

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

Re: insert html elements before a field

Post by jsetzer » 2020-06-08 12:45

Hi,

appending custom html to the bottom of DV or prepending html to the top is not hard by just modifying the given $html variable. But here, the challenge is to place the custom html above the field.

If this is a normal field (and not a lazy loaded lookup) you can do it this way:

file: hooks/TABLENAME.php

Code: Select all

function TABLENAME_dv($selectedID, $memberInfo, &$html, &$args)
{
	$fieldname = "resource_type"; // TODO: change $fieldname
	
	$html .= '<p id="my_custom_paragraph" class="well">my <i>custom paragraph</i> with <b>bold</b> text</p>';
	$html .= '<script>$j("#my_custom_paragraph").prependTo($j("#' . $fieldname . '").closest(".form-group"))</script>';
	
	// ...
}

Result

chrome_AUXQ38io6K.png
chrome_AUXQ38io6K.png (4.76 KiB) Viewed 2139 times
Inserted above field named "resource_type".

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

fgazza
Veteran Member
Posts: 205
Joined: 2019-04-30 17:37

Re: insert html elements before a field

Post by fgazza » 2020-06-12 13:44

Many thanks!

with your suggestion I prepared the form correctly (i set my code into div tag and not into p tag because i have several paagraph and an image) but unfortunately if I view the form itself with the "print" option (print view), my custom html code is displayed below the form fields.

I would be grateful for your help.

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 348
Joined: 2018-03-04 09:30
Location: David

Re: insert html elements before a field

Post by D Oliveira » 2020-06-12 14:04

fgazza wrote:
2020-06-12 13:44
Many thanks!

with your suggestion I prepared the form correctly (i set my code into div tag and not into p tag because i have several paagraph and an image) but unfortunately if I view the form itself with the "print" option (print view), my custom html code is displayed below the form fields.

I would be grateful for your help.
could try modifying the tablename_DV.html template in templates folder and see how it goes

fgazza
Veteran Member
Posts: 205
Joined: 2019-04-30 17:37

Re: insert html elements before a field

Post by fgazza » 2020-06-12 14:40

Thank you but as I renew many times my app generating new files by appgini tool i prefer a solution that affect only the hook file.

Post Reply