Implement Tooltips into Forms
Overview
This article introduces how to implement tooltips into records of Kintone Apps by using popModal. The usage of tooltips is a great alternative to using labels to save space in the form.
popModal
popModal is a jQuery plug-in for showing tooltips, titles and modal dialogs. This article uses the hintModal feature of the library to display tooltips.
Prepare the App
Create the Form
Create an App with the following fields.
Field Type | Field Name | Field Code |
---|---|---|
User Selection | Ordered By: | ordered_by |
Check Box | Your lunch order: | lunch_order |
Blank Space | - | add |
We will customize the App so that the hint icon will appear in the blank space. When inputting data for a new record, an exclamation icon will appear that when hovered over, will display further details of the content of the App. This example will display restaurant information, which employee will pay for the lunch, and the individual prices of each menu item.
Set the Libraries
JavaScript
Set the following URL into the App's JavaScript and CSS Customization settings , under the Upload JavaScript for PC option.
- https://js.kintone.com/jquery/2.2.4/jquery.min.js
- https://js.kintone.com/popmodal/1.26/popModal.min.js
CSS
Set the following URL into the App's JavaScript and CSS Customization settings , under the Upload CSS File for PC option.
- https://js.kintone.com/popmodal/1.26/popModal.min.css
- https://js.kintone.com/font-awesome/v5.2.0/css/fontawesome-all.min.css
Sample Code
Prepare the following JavaScript code in a text editor and navigate to the Kintone App's settings. Upload the file into the Upload JavaScript for PC option of the JavaScript and CSS Customization settings .
|
|
The JavaScript and CSS Customization settings page should look like the following.
Attention
Caution: The order in which Javascript and CSS are uploaded to an app matters. In this example, ensure that the jQuery and popModal Javascript imports are uploaded before the custom Javascript file. You can change the order of uploads by clicking and dragging on the arrows for each item on the Upload Javascript / CSS page.
After saving the settings and clicking on Update App, add a new record. An icon with an exclamation mark should appear where the Blank space field is located. Hover over the icon to view the tooltip.
Code Explanation
Event Handling
|
|
The tooltips are implemented when the app.record.create.show or the app.record.edit.show events are triggered.
Create the Tooltip Contents
|
|
An HTML element including the tooltip details is created with jQuery. The icon of the tooltip is set as an exclamation mark. The text contents of the tooltip is set inside the <div>
tag.
Create the Tooltip
|
|
The created HTML is converted into a tooltip.
Implement the Tooltip
|
|
The getSpaceElement method is used to retrieve the element of the Blank space fields.
Return the Event Object
|
|
Return the event object to apply the changes to the form.