Documentation Index
Fetch the complete documentation index at: https://docs.joyfill.io/llms.txt
Use this file to discover all available pages before exploring further.
DocumentEditor Field Access
The DocumentEditor provides several convenient properties and methods to access and work with form fields programmatically.
Get Updated Document at Any Time
You can access the current document state in two ways:
1. Direct Access from DocumentEditor
// Get the current document with all updates
let currentDocument = documentEditor.document
2. From onChange Event
func onChange(changes: [Change], document: JoyDoc) {
// The document parameter contains the fully updated document
let updatedDocument = document
// This is the same as documentEditor.document at this moment
print("Document updated with \(changes.count) changes")
}
allFields - Get All Fields
let documentEditor = DocumentEditor(document: document)
// Get all fields in the document
let fields = documentEditor.allFields
print("Total fields: \(fields.count)")
// Iterate through all fields
for field in documentEditor.allFields {
print("Field: \(field.title ?? "No title") - Type: \(field.fieldType)")
}
field(fieldID:) - Get Specific Field
// Get a specific field by ID
if let field = documentEditor.field(fieldID: "textField1") {
print("Field title: \(field.title ?? "No title")")
print("Field type: \(field.fieldType)")
}
getFieldIdentifier - Field Context Access
The getFieldIdentifier(for:) method provides complete context information about a field, which is essential for the Change API and field operations.
// Get field identifier by field ID
let fieldIdentifier = documentEditor.getFieldIdentifier(for: "textField1")
print("Field ID: \(fieldIdentifier.fieldID)")
print("Page ID: \(fieldIdentifier.pageID ?? "No page")")
print("File ID: \(fieldIdentifier.fileID ?? "No file")")
print("Identifier: \(fieldIdentifier.identifier ?? "No identifier")")
print("Position ID: \(fieldIdentifier.fieldPositionId ?? "No position")")
Change API
Programmatic updates to a JoyDoc via the editor. Apply multiple updates in one call.
The Change API uses the change(changes:) method on DocumentEditor to apply programmatic updates to form fields. All changes are applied as an array of Change objects.
// Apply changes to the form
documentEditor.change(changes: [change1, change2, change3])
Supported Change Types
| Target | Description | Usage |
field.update | Update field value | Set text, numbers, dates, selections |
field.value.rowCreate | Create table row | Add new rows to tables |
field.value.rowUpdate | Update table row | Modify existing table rows |
field.value.rowDelete | Delete table row | Remove rows from tables |
field.value.rowMove | Reorder table rows | Change row positions |
Basic Field Update
let fieldId = "textField123"
//Get field identifier
let id = editor.getFieldIdentifier(for: fieldId)
//Create change object
let change = Change(
v: 1,
sdk: "swift",
target: "field.update",
_id: editor.documentID ?? "",
identifier: editor.documentIdentifier,
fileId: id.fileID ?? "",
pageId: id.pageID ?? "",
fieldId: id.fieldID,
fieldIdentifier: nil,
fieldPositionId: id.fieldPositionId ?? "",
change: ["value": "Updated value"],
createdOn: Date().timeIntervalSince1970
)
// Apply the change
editor.change(changes: [change])
Create table row example
let tableFieldId = "tableField1"
let id = editor.getFieldIdentifier(for: tableFieldId)
let newRow = Change(
v: 1,
sdk: "swift",
target: "field.value.rowCreate",
_id: editor.documentID ?? "",
identifier: editor.documentIdentifier,
fileId: id.fileID ?? "",
pageId: id.pageID ?? "",
fieldId: id.fieldID,
fieldIdentifier: nil,
fieldPositionId: id.fieldPositionId ?? "",
change: [
"row": [
"_id": UUID().uuidString,
"cells": [:]
],
"targetRowIndex": 0
],
createdOn: Date().timeIntervalSince1970
)
editor.change(changes: [newRow])