Path: blob/main/doc/tutorials/intermediate/create_form.md
2012 views
Create a Form with HoloViz Panel
Welcome to the "Create a Form" tutorial! In this guide, we will create an interactive and fully functional form using HoloViz Panel. By the end of this tutorial, you'll have built a form with validation that captures user input and processes it effectively. This tutorial adopts the param.Parameterized
approach to ensure the form is extensible and maintainable.
Key Objectives
Create an Interactive Form: Build a form to capture Name, Email, and an optional Message.
Validate User Input: Ensure the form inputs meet specified criteria.
Submit Data: Simulate sending the form data for further processing.
Implementation
Below is a step-by-step breakdown of the code to create the form.
1. Import Dependencies
We use panel
to build the interactive components and param
for structured data handling and validation.
2. Define Form Text and Icons
We add some static elements to make the form visually appealing.
3. Create a Parameterized Form State Class
The FormState
class handles form inputs, validation, and state management.
4. Build the Form Layout
We use pn.widgets
to create form inputs and buttons.
5. Serve the Application
Extend Panel with notifications, create the form, and mark it .servable()
.
Finally you can serve the application with
Summary
In this tutorial, we built a fully functional form with the following features:
User Input Fields: Capturing Name, Email, and an optional Message.
Input Validation: Ensuring required fields are filled and valid.
Form Submission: Resetting the form upon successful submission and displaying notifications.
By structuring our app with param.Parameterized
, we ensured that the form is easy to maintain and extend in the future.
Full Code
Here's the complete code for reference: