56 lines
3.4 KiB
Plaintext
56 lines
3.4 KiB
Plaintext
---
|
||
description: Rapport form Blade templates — resolution order, patterns, guardrails
|
||
globs: resources/views/form/**/*.blade.php
|
||
alwaysApply: false
|
||
---
|
||
|
||
# Form views (`resources/views/form`)
|
||
|
||
## View selection (must match `FormController::deliverform`)
|
||
|
||
Resolution order for **form** links:
|
||
|
||
1. `form.{partition}.{form_id}` — Blade at `form/{partition}/{form_id}.blade.php` (controller uses `is_file` on a deploy-specific base path; if checks fail, overrides are skipped).
|
||
2. `form.{form_id}` — `form/{form_id}.blade.php` at folder root.
|
||
3. `form.common-enrollmentform` if `$formdata->form_type === 'enrollment_form'`.
|
||
4. `form.common-planexecution` if `$formdata->form_type === 'plan_vs_execution'`.
|
||
5. Else `form.common`.
|
||
|
||
**List** (`link_type == 'list'`): `form.{partition}.list-{form_id}` → `form.list-{form_id}` → `form.{partition}.list` → `form.list`. History views use similar `View::exists` patterns in the same controller.
|
||
|
||
If a new Blade’s name/path does not match this cascade, it will not load.
|
||
|
||
## Default implementation
|
||
|
||
- Prefer copying or extending **`form.common`**: `@foreach ($questions as $question)` and `@switch ($question->type)` (`hidden`, `text`, `email`, `tel`, `date`, `number`, `textarea`, `dropdown`, `radio`, `radiometrix`, `checkbox`, `file`, `multitextbox`).
|
||
- Use **`$question->code`** for `name` / `id` (`id="field-{{ $question->code }}"`). Checkbox names use `[]` where existing templates do.
|
||
- Preserve **`$questions`**, **`$form` / `$formdata`**, **`$form_id`**, **`$id`**, and optional **`$mode`**, **`$demo`**, **`$additional`** — do not rename without updating the controller and all templates.
|
||
|
||
## Layout and assets
|
||
|
||
- Reuse `@include('layouts.shared/title-meta', ...)`, `layouts.shared/head-css`, `layouts.shared/footer-script`, existing SweetAlert2 paths, `#pageloader`, and Bootstrap card / `account-pages` structure used in sibling blades.
|
||
|
||
## Submit behaviour
|
||
|
||
- Standard submit form: `id="report-form"`, `method="POST"`, `action="/form/submit"`, `enctype="multipart/form-data"`, `@csrf`, hidden `form_id`, optional hidden `id`. Client-side submit typically POSTs `FormData` to **`/form/ajaxsubmit`** with SweetAlert2 feedback — match `form.common` unless the page is explicitly non-submit (e.g. list-only).
|
||
|
||
### Required submit handler + notifications (SweetAlert2)
|
||
|
||
- For any submit-capable form Blade (`link_type == 'form'`), prefer using the exact `$('#report-form').on('submit', function(event){ ... })` pattern from `form.common`:
|
||
- prevent default submit
|
||
- show/hide `#pageloader`
|
||
- `POST` `new FormData($('#report-form')[0])` to `/form/ajaxsubmit`
|
||
- Use **SweetAlert2 (`Swal.fire`)** for all user-facing success/error messages in JS (no `alert()`, no console-only messages).
|
||
|
||
## Partition / client overrides
|
||
|
||
- Client-specific templates live under **`form/rapport-{client}/`**. File name must be **`{form_id}.blade.php`** (or the `list-` / `-history` variants the controller checks) so Laravel’s `form.{partition}.{form_id}` resolves.
|
||
|
||
## Do not
|
||
|
||
- Add a new stack (SPA framework, new global layout) or new submit URLs without **routes** and **`FormController`** changes.
|
||
- Remove approval / read-only behaviour (`is_approval`, file upload vs preview) when copying from `common` unless the task explicitly requires it.
|
||
- Refactor unrelated modules or shared layouts “while you’re here”.
|
||
|
||
When unsure, open **`form.common`** and the closest sibling template (e.g. **`form.common-planexecution`**, **`form.list`**) and mirror their structure.
|