This example shows how to render arbitrary HTML in Form View using HTML field
Use Case
I have a DocType named Driver in my hypothetical Ride Management app. I want to show a summary of rides by a driver right in the form view like shown below:
The details include the number of rides the driver has completed (think Uber đ), total revenue from those rides, and average rating.
The Backend API
This data is returned from backend by an API script (/api/method/get-driver-summary) in this format:
This script takes driver_name as argument.
Letâs see how we can use the HTML type field and some JavaScript (Client Script) to achieve this!
Adding HTML Field
I will add a new section and inside that an âHTMLâ field (NOT âHTML Editorâ):
If you want static HTML content to be displayed, you can add it to the Options property of this field:
But we want to go a step further: we want to dynamically set this HTML based on the data we receive for this driver from the backend!