Embed a form builder with Kotlin
In this guide, we'll show how to embed a form builder with Kotlin using Joyfill’s Kotlin form builder SDK, and learn how to render your first form in minutes.
You can think of Joyfill as a sort of Stripe or Twilio, but for forms.
We offer four libraries entirely build in kotlin multiplatform
io.joyfill:joyfill-compose: The main library for integrating Joyfill into your Compose app. This library includes all the necessary UI components for displaying and interacting with Joyfill documents.
io.joyfill:joyfill-models: A library for integrating Joyfill models into your Kotlin app.
io.joyfill:joyfill-builder: A library for creating documents programmatically in kotlin
io.joyfill:joyfill-api: A library for all the network interactions with the Joyfill API.
Setup
Please see our Overview and Getting Started Guide
Project Requirements
Note: userAccessTokens & identifiers will need to be stored on your end (usually on a user and set of existing form field-based data) in order to interact with our API and UI Components effectively
See our API Documentation for more information on how to interact with our API.
Install Dependency
Add the following maven coordinates to your dependencies in your build.gradle.kts file.
Select the SDK version that you want to use.
Note: We recommend using the default (latest) SDK version, but you can choose an older version if needed.
Choose the Joyfill libraries you want to use.
Getting Started
Show a Joyfill Document with the Form Composable
See our example project for more details.
Form Params
- mode: 'Mode.fill' | 'Mode.readonly'- Enables and disables certain JoyDoc functionality and features. 
- Default is - Mode.fill.
- Options - fillis the mode where you simply input the field data into the form
- readonlyis the mode where everything in the form is set to read-only.
 
 
- document: Document- The JoyDoc JSON object to load into the SDK. Must be in the JoyDoc JSON data structure. 
- The SDK uses object reference equality checks to determine if the - docor any of its internal- pagesor- fieldshave changed in the JSON. Ensure you’re creating new object instances when updating the document, pages, or fields before passing the updated- docJSON back to the SDK. This will ensure your changes are properly detected and reflected in the SDK.
 
- pageID: String- Specify the page to display in the form. 
- Utilize the - _idproperty of a Page object. For instance,- page._id.
- If page is not found within the - docit will fallback to displaying the first page in the- pagesarray.
- You can use this property to navigate to a specific page in the form. 
 
- onChange: (event: ChangeEvent) -> Unit- Used to listen to any field change events. 
- event.changelogs: List<ChangeLog>- Can contain one or more of the changelog object types supported. Learn more about changelogs 
 
- event.document: Document- Fully updated JoyDoc JSON structure with changes applied. 
 
 
- onUpload: suspend (event: FieldEvent) -> List<String>- Used to listen to file upload events. 
- Specifies information about the uploaded file. 
 
- onFocus: (event: FieldEvent) -> Unit- Used to listen to field focus events. 
- eventSpecifies information about the focused field.
- blur: Function- Triggers the field blur event for the focused field. 
- If there are pending changes in the field that have not triggered the - onChangeevent yet then the- e.blur()function will trigger both the change and blur events in the following order: 1)- onChange2)- onBlur.
- If the focused field utilizes a modal for field modification, ie. signature, image, tables, etc. the - e.blur()will close the modal.
 
 
- onBlur: (event: FieldEvent) -> Unit- Used to listen to field focus events. 
- eventSpecifies information about the blurred field.
 
- onFieldChange: (event: FieldEvent) -> Unit- Used to listen to individual micro field change events. 
- eventSpecifies information about the field change.
 
ChangeEvent Properties
Field Events:
- Text, Textarea, Number - onFocus(params: object, e: object)is fired when the field is focused.
- onChangeis fired when the field value is modified.
- onBluris fired when the field is blurred.
 
- Date, Dropdown - onFocusis fired when the field is pressed and selection modal is displayed.
- onChangeis fired when the field value is modified.
- onBluris fired when the field is blurred and the selection modal is closed.
 
- Multiselect - onFocusis fired when an option is selected or unselected for the first time on the field.
- onChangeis fired when an option is selected or unselected in the field.
 
- Chart - onFocusis fired when “view” button is pressed and modal is displayed.
- onChangeis fired when the field value is modified.
- onBluris fired when modal is closed.
 
- Image - onFocusis fired when “view” button is pressed and modal is displayed.- An empty image field that is focused will also trigger the - onUploadAsyncrequest.
- A populated image field that is focused will trigger the image modal to open. 
 
- onChangeis fired when the field images are uploaded or removed.
- onBluris fired when modal is closed.
 
- Signature - onFocusis fired when open modal button is pressed and modal is displayed.
- onChangeis fired when the field value is modified.
- onBluris fired when the modal is closed.
 
- Table - onFocusis fired when “view” button is pressed and modal is displayed.
- onBluris fired when modal is closed.
- Table Cells - Text Cell - onFocusis fired when the cell is focused.
- onChangeis fired when the cell value is modified.
- onBluris fired when the cell is blurred
 
- Dropdown Cell - onFocusis fired when the cell is pressed and selection modal is displayed.
- onChangeis fired when the field value is modified.
- onBluris fired when the cell is blurred and the selection modal is closed.
 
- Image Cell - onFocusis fired cell is pressed and modal is displayed.- An empty image cell that is focused will also trigger the - onUploadAsyncrequest.
- A populated image cell that is focused will trigger the image modal to open. 
 
- onChangeis fired when the cell images are uploaded or removed.
- onBluris fired when modal is closed.
 
 
 
IMPORTANT NOTE: JoyDoc SDK onFocus, onChange and onBlur events are not always called in the same order. Two different fields can be triggering events at the same time. For instance, if you have Field A focused and then focus on Field B, the Field B onFocus event could be fired before the Field A onBlur event. Always check the event params object ids to match up the associated field events.
Kotlin form builder guide summary
Embarking on a Kotlin cross-platform project with Joyfill entails leveraging a suite of robust libraries designed to seamlessly integrate document management into your application. With offerings like joyfill-compose, joyfill-models, joyfill-builder, and joyfill-api, developers gain access to comprehensive tools for UI integration, model incorporation, document creation, and network interaction. By following the outlined project requirements and installing dependencies, developers can swiftly immerse themselves in the Joyfill ecosystem.
The process of getting started is straightforward, with the ability to display Joyfill documents using the Form Composable feature. By specifying parameters such as mode, document, pageID, and implementing event listeners like onChange and onUpload, developers can customize the interaction with Joyfill documents to suit their application's needs.
Moreover, the Joyfill SDK offers a versatile range of event triggers for various field types, ensuring comprehensive control over user interactions. From text fields to charts and images, developers can harness onFocus, onChange, and onBlur events to facilitate seamless user experiences.
With additional resources such as sample applications and the Kotlin Joyfill API, developers have access to further guidance and documentation to aid in the integration and utilization of Joyfill functionalities within their projects.
Related Articles
You may also be interested in reading the following related form builder guides:
Embed a form builder with Javascript
Embed a form builder with React
Embed a form builder with React Native

