A button that provides submission functionality for the assigned document.
`AssignedDocumentSubmissionButton` enables students to submit and withdraw assigned documents.
The button fetches document data from ClassKit and updates its appearance and behavior based on the current
submission status. The button shows loading states during both initial data loading and submission processing.
You can customize the submission process using view modifiers that execute at key points in the submission lifecycle.
Use the modifiers to either validate or prepare documents before an action or update your app after an action completes:
For submissions, use:
- <doc://com.apple.documentation/documentation/swiftui/view/onassigneddocumentwillsubmit(_:)> to validate the document before submission.
- <doc://com.apple.documentation/documentation/swiftui/view/onassigneddocumentdidsubmit(_:)> to update your interface or log analytics after a successful submission.
For withdrawing submissions use:
- <doc://com.apple.documentation/documentation/swiftui/view/onassigneddocumentwillwithdraw(_:)> to confirm the withdrawal action with the student or prepare your app state.
- <doc://com.apple.documentation/documentation/swiftui/view/onassigneddocumentdidwithdraw(_:)> to update your interface or notify the student that their document is no longer submitted.
The following example shows how to create an assigned document submission button and customize its behavior
with validation and completion actions:
```swift
// Create a basic submission button
AssignedDocumentSubmissionButton(documentURL: documentURL)
// Create menu item with validation and logging
// Provide closures to validate document submissions and respond to completed submissions:
AssignedDocumentSubmissionButton(documentURL: documentURL)
.onAssignedDocumentWillSubmit { url in
// Validate the assigned document before submission
guard await validateDocument(url) else {
await showAlert("Please complete all sections before submitting")
return false // Prevents submission
}
return true // Allows submission to continue
}
.onAssignedDocumentDidSubmit { url in
// Handle successful submission
logEvent("Assigned document submitted successfully!")
}