First you have to fill the comment attribute in the field definition you want the tooltip to appear. Example: db.define_table('board', Field('message',comment='Let your message here.'))
If you do only this, the tip will appear on the right side of field when the form is genearated via CRUD or SQLFORM. And remember if you want to put html code in comment you should use HELPERS to get it rendered properly.
Example: db.define_table('recados', Field('mensagem',comment=SPAN('Let here your ', B('message')))
Now the fun part!
You will need a jquery plugin to show the tip so you may google for it and pick one. Or you can use this http://jquery.bassistance.de/tooltip/jquery.tooltip.zip See it what it looks like here http://jquery.bassistance.de/tooltip/demo/
Extract jquery.tooltip.min.js and jquery.tooltip.css to static folder. Edit web2py_ajax.html and include the call for these files. Something like this:
{{
response.files.insert(0,URL(r=request,c='static',f='jquery.js'))
response.files.insert(1,URL(r=request,c='static',f='calendar.css'))
response.files.insert(2,URL(r=request,c='static',f='calendar.js'))
response.files.insert(3,URL(r=request,c='static',f='jquery.tooltip.min.js'))
response.files.insert(3,URL(r=request,c='static',f='jquery.tooltip.css'))
.......
Now you have this a script on every page you want tooltips:
<script type="text/javascript">
$(function() {
$(".w2p_fw").each(function (){ //iterates over all form widgets
$(this).attr('title',$(this).next().html()); // set title for the widget taken from the comment column
$(this).next().html(''); // clear the comment
$(this).tooltip(); // create the tooltip with title attribute set
});
});
</script>
Done! Comment column will be converted into nice tooltips.
Note: you may include this script in web2py_ajax.html or layout.html to reuse the code. Or you may put this code in another file and include it when needed, maybe this is the better way.
Comments (5)
0
aliz0611 8 years ago
I've hacked kmouts's solution to work with bootstrap 3.
0
javi 10 years ago
Great tip, but for me the comment of kmouts is a nice solution, i hacked it to make it appear the help icon in the same col of label and aligned to right:
1
kmouts 11 years ago
Great tip!
This is how I manipulated it to use bootstrap help icon and its css:
0
villas 14 years ago
Edit Meeting
0
villas 14 years ago