Fix Form_Utils to use component.$sid() instead of data-sid selector

Add response helper functions and use _message as reserved metadata key

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-12-23 22:38:48 +00:00
parent 678ff17ad6
commit 69af4e87d4
5 changed files with 73 additions and 14 deletions

View File

@@ -97,17 +97,21 @@ class Frontend_Clients_Edit {
### Change
Adopted unified `response_error()` function with error code constants. Same constant names on server and client for zero mental translation.
**Note**: The fragmented helper functions (`response_form_error()`, `response_auth_required()`, etc.) shown in earlier documentation were a planned design that was superseded before implementation. Only `response_error()` exists.
Adopted unified `response_error()` function with error code constants, plus convenience helpers. Same constant names on server and client for zero mental translation.
### Pattern
```php
// Server - single function with constants
// Server - base function with constants
return response_error(Ajax::ERROR_VALIDATION, ['email' => 'Invalid']);
return response_error(Ajax::ERROR_NOT_FOUND, 'Project not found');
return response_error(Ajax::ERROR_UNAUTHORIZED); // Auto-message
// Convenience helpers (recommended for clarity)
return response_form_error('Validation failed', ['email' => 'Invalid']);
return response_not_found('Project not found');
return response_unauthorized();
return response_auth_required();
return response_fatal_error('Something went wrong');
```
```javascript

View File

@@ -912,7 +912,7 @@ async on_load() {
// Controller: save() receives all form values, validates, persists
#[Ajax_Endpoint]
public static function save(Request $request, array $params = []) {
if (empty($params['title'])) return response_form_error('Error', ['title' => 'Required']);
if (empty($params['title'])) return response_form_error('Validation failed', ['title' => 'Required']);
$record = $params['id'] ? My_Model::find($params['id']) : new My_Model();
$record->title = $params['title'];
$record->save();