Skip to content

Commit 65ad147

Browse files
committed
docs: add docs for precognition
1 parent 7827a97 commit 65ad147

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed

docs/0_general/4_precognition.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
title: Precognition
3+
description: Real-time field validation with HTMX
4+
---
5+
6+
Precognition enables real-time field validation as users type, providing immediate feedback without requiring a full form submission. This feature is only available when using HTMX mode.
7+
8+
## Prerequisites
9+
10+
1. **HTMX Mode**: Your form must use HTMX mode
11+
2. **Idiomorph Extension**: Required for DOM morphing
12+
13+
Install [HTMX](https://htmx.org/) and the [Idiomorph extension](https://htmx.org/extensions/idiomorph/).
14+
15+
## Configuration
16+
17+
Enable precognition in your config:
18+
19+
```php
20+
// site/config/config.php
21+
22+
return [
23+
'tobimori.dreamform' => [
24+
'mode' => 'htmx',
25+
'precognition' => true,
26+
],
27+
];
28+
```
29+
30+
## How It Works
31+
32+
- Fields validate automatically as users type or change values
33+
- Text fields wait 500ms after typing stops before validating
34+
- Select/radio/checkbox fields validate immediately on change
35+
- Only the changed field is validated, not the entire form
36+
- No data is saved during precognitive validation
37+
38+
## Partial Submissions
39+
40+
When precognition is enabled, you can also enable partial submissions:
41+
42+
```php
43+
// site/config/config.php
44+
45+
return [
46+
'tobimori.dreamform' => [
47+
// ...
48+
'partialSubmissions' => true,
49+
],
50+
];
51+
```
52+
This automatically saves each field's value as the user fills it out. This helps track progress for abandoned forms and prevents data loss from failed submissions.

docs/5_developers/7_under-the-hood.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,28 @@ title: Under the Hood
33
description: Technical details about how DreamForm works
44
---
55

6-
Learn about the internal workings of DreamForm, including the submission lifecycle, validation process, and architecture decisions.
6+
Learn about the internal workings of DreamForm, including the submission lifecycle, validation process, and architecture decisions.
7+
8+
## Submission Lifecycle
9+
10+
### Regular Submission
11+
12+
1. **Request Reception**: Form receives POST request
13+
2. **Session Initialization**: Creates or retrieves submission session
14+
3. **Guard Execution**: Security guards validate the request
15+
4. **Field Validation**: Each field validates its value
16+
5. **Hook Execution**: `dreamform.submit:before` hooks run
17+
6. **Action Processing**: Actions execute in defined order
18+
7. **Submission Storage**: Data saved to submissions folder
19+
8. **Success Handling**: Redirects or displays success message
20+
9. **Hook Completion**: `dreamform.submit:after` hooks run
21+
22+
### Precognition Lifecycle
23+
24+
When precognition is enabled, field validation requests follow a simplified flow:
25+
26+
1. **Precognitive Request**: Receives POST with `?precognition=true` (through HTMX)
27+
2. **Minimal Guards**: Only precognitive guards execute
28+
3. **Single Field Validation**: Only the triggering field is validated
29+
4. **Response Generation**: Returns updated field HTML
30+
5. **No Side Effects**: No hooks, actions, or data storage

0 commit comments

Comments
 (0)