# `tko_investor` / ` ` and textarea interaction

This document explains how to use the **TKO investor fields** (`tko_investor*`) on the Company edit screen, and how `tko_investor2` interacts with **dynamic textarea** fields.

## What are `tko_investor*` fields?

- **Field naming**: any dynamic field whose name starts with `tko_investor` (example: `tko_investor`, `tko_investor1`, `tko_investor2`, `tko_investor3`, …).
- **Input type**: these fields are treated as “investor pickers” when `input_type == text`.
- **Stored value**: the saved value is the **EDM investor id** (`edm_id`), not the label.

On Company **profile** (read-only), the UI resolves the stored `edm_id` into an investor `short_name`. If the id cannot be resolved, the raw value is displayed (highlighted as “unknown”).

## How to use `tko_investor` and `tko_investor2` (Company edit)

On the **Company edit** page:

- **Where**: any field whose name starts with `tko_investor` is rendered with a remote searchable dropdown.
- **Search**: type at least a couple characters; results are fetched from EDM investors.
- **Select**: pick the investor/fund from the list.
- **Saved value**: when you select an item, the form submits and stores `edm_id` (the dropdown shows `short_name` for usability).
- **Clear**: you can clear the selection; the stored value becomes empty/null (and server-side rules apply).

### Data/validation rules (server-side)

For dynamic fields whose name starts with `tko_investor`, validation is enforced as:

- `nullable|string|exists:edm_investors,edm_id`

Meaning: the value must be empty OR match an existing row in `edm_investors.edm_id`.

## Textarea interaction: the `tko_investor2` “lock” rule

`tko_investor2` has a special meaning for the **Company edit** screen only.

### What happens

When editing a company:

- If `company.data['tko_investor2']` is **not empty**,
- then **all dynamic textarea fields whose name ends with `2`** are marked **non-editable** and are **excluded from the edit form**.

Practically: you won’t be able to change those textareas from the edit page while `tko_investor2` is filled.

### Scope (important)

- Applies **only** on the route `companies.edit` (edit form rendering).
- Applies only to **dynamic fields** with:
  - `input_type == textarea`
  - name ends with `2` (case-insensitive check on the suffix)
- It does **not** remove or alter the stored values in the database; it only prevents editing them in the UI.

### How the UI enforces it

On page render, the backend sets `no_edit = true` on the matching textarea dynamic fields. The edit form component then omits any field where `no_edit` is true, so the textarea is not shown as editable.

## Examples

### Example A: `tko_investor2` is empty

- `tko_investor2 = ""`
- `investment_thesis2` (textarea) is **editable**
- `investment_thesis1` (textarea) is **editable**

### Example B: `tko_investor2` is filled

- `tko_investor2 = "EDM_12345"`
- `investment_thesis2` (textarea) becomes **read-only / hidden from edit**
- `investment_thesis1` (textarea) stays **editable**

## Developer notes (where this is implemented)

- **Investor picker on edit**: `lncshared/resources/assets/js/components/fields/inputs-list.vue` routes `tko_investor*` (text) to `input-edm-fund.vue`.
- **Remote EDM search + saved value**: `lncshared/resources/assets/js/components/forms/input-edm-fund.vue` uses:
  - `POST /api/search/edm_investors` for search
  - `GET /api/edm_investor_lookup` to resolve a default stored `edm_id` to a `short_name`
- **Textarea lock rule**: `app/Models/Company.php` in `booted()` / `retrieved()`:
  - checks `tko_investor2`
  - sets `no_edit = true` for textarea fields whose name ends with `2`
- **Validation**: `app/Models/Company.php` (`Company::rules()`), for any dynamic key that starts with `tko_investor`.


## Possible list of fields: 
- InvestmentBackground2, 
- InvestmentRationale2, 
- RiksMitigants2, 
- StrategicAndValueCreation2, 
- ExitProcess2 

