> ## 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.

# Populating and Extracting Data

## 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**

```swift theme={null}
// Get the current document with all updates
let currentDocument = documentEditor.document
```

**2. From onChange Event**

```swift theme={null}
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**

```swift theme={null}
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**

```swift theme={null}
// 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.

```swift theme={null}
// 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.

```swift theme={null}
// 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**

```swift theme={null}
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**

```swift theme={null}
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])
```
