vault/ui/app/forms
Vault Automation 8cf1370eb8
[UI]: Ember Data Migration Identity (#15194) (#15683)
* [UI]: Ember Data Migration Identity List and Details (#15157)

* Update identity views edm

* Use model directly

* Code cleanup!

* Refresh list view if deleted

* Update identity detail page

* Identity show..

* Have different method types

* Update delete...

* [UI] Ember Data Migration: Identity forms, show, edit, create and list routes (#15291)

* Identity forms...

* Fetch entities and groups in route

* Update forms to have edit

* Fix breadcrumbs

* Update save to use api service method

* Merge entities form...

* Update aliases

* Entity and group show routes

* Fix create / save action

* Add alias form.

* Fix some tests!

* Fix tests and update capability check

* WIP fixing tests...

* Fixes some details page bugs

* Edit form delete actions..

* Passing all tests!!

* Refactor some utils

* Update to class based syntax

* Form label updates

* Remove unused onSuccess

* [UI] Identity EDM code cleanup (#15608)

* Fix cancelLink action

* Update tests to have the correct args

* Ensure add alias button shows when alias does not exist

* Fix lookup input

* Fix other tabs and pages..

* Address comments

Co-authored-by: Kianna <30884335+kiannaquach@users.noreply.github.com>
2026-06-23 07:12:28 -07:00
..
auth Backport [UI] Ember Data Migration - Core Addon - Search Select into ce/main (#14952) 2026-05-22 09:58:00 -06:00
identity [UI]: Ember Data Migration Identity (#15194) (#15683) 2026-06-23 07:12:28 -07:00
keymgmt Ember Data Migration - Keymanagement Provider views | VAULT-44905 (#14816) (#14828) 2026-05-15 17:39:49 +00:00
mfa [UI] Ember Data Migration - MFA (#14721) (#14894) 2026-05-20 13:36:35 +00:00
oidc [UI] Ember Data Migration - OIDC Assignments (#14491) (#14657) 2026-05-11 08:37:31 -06:00
secrets UI: Update kv max_version validation (#14430) (#14455) 2026-05-04 15:10:29 +00:00
ssh VAULT-44224 - Cleans up SSH-related code and remove unused adapters and models (#15117) (#15120) 2026-06-02 20:59:19 +05:30
sync [UI] VAULT-42756 - Secret sync WIF implementation (#14001) (#14167) 2026-04-22 12:46:13 +05:30
totp [UI] Ember Data Migration - TOTP Secrets Engine Views | VAULT-44225 (#14933) (#14983) 2026-05-26 11:31:44 +05:30
transform Backport [UI] Ember Data Migration - Transform Role and Transformation views | VAULT-45708 | VAULT-45709 into ce/main (#15234) 2026-06-05 22:28:33 +05:30
transit UI: Ember Data Migration: Transit Secrets Engine (#15195) (#15232) 2026-06-08 11:27:02 -04:00
v2 UI: V2 Forms Override Logic (#15102) (#15648) 2026-06-18 11:26:31 -07:00
custom-message.ts license: update headers to IBM Corp. (#10229) (#10233) 2025-10-21 15:20:20 -06:00
form.ts [UI] Ember Data Migration - PKI Configuration (#10328) (#10523) 2025-11-18 09:42:22 -07:00
mount.ts UI: fix bug when mounting external kv version & empty payload when tuning external versions (#13361) (#13450) 2026-03-26 16:58:42 -04:00
open-api.ts Update eslint console rule (#11883) (#11948) 2026-01-23 13:26:41 -08:00
policy.ts UI: Ember Data migration: Policies (#14710) (#14787) 2026-05-13 21:09:50 +00:00
README.md [UI] API Service Error Parsing (#30454) 2025-04-30 11:44:19 -06:00

Background

The Form class was created as a replacement for form related functionality that previously lived in Ember Data models. Given that the FormField component was designed around the metadata that was defined on model attributes, it was imperative to preserve this pattern while moving the functionality to a dependency-free native javascript solution.

Usage

The Form class is intended to be extended by a class that represents a particular form in the application.

export default class MyForm extends Form {
  declare data: MyFormData;

  // define form fields
  name = new FormField('name', 'string');
  secret = new FormField('secret', 'string', {
    editType: 'kv',
    keyPlaceholder: 'Secret key',
    valuePlaceholder: 'Secret value',
    label: 'Secret (kv pairs)',
    isSingleRow: true,
    allowWhiteSpace: true,
  });

  // define validations
  validations: Validations = {
    name: [{ type: 'presence', message: 'Name is required.' }],
  };

  // if serialization is needed override toJSON method
  toJSON() {
    const trimmedName = this.data.name.trim();
    return super.toJSON({ ...this.data, name: trimmedName });
  }
}

Form data is set to the data object on the class and can be initialized with defaults or server data when editing by passing an object into the constructor.

// create route
model() {
  return new MyForm({ name: 'Default name' });
}

// edit route
async model() {
  const data = await this.api.fetchSomeData();
  return new MyForm(data);
}

The route model (MyForm instance) can be passed into the form component in the same manner as an Ember Data model and the formFields can be looped to render FormField components.

{{#each @form.formFields as |field|}}
  <FormField @attr={{field}} @model={{@form}} @modelValidations={{this.validations}} />
{{/each}}

To validate the form and access the data use the toJSON method.

// save method of form component
async save() {
  try {
    const { isValid, state, invalidFormMessage, data } = this.args.form.toJSON();
    this.validations = isValid ? null : state;
    this.invalidFormMessage = invalidFormMessage;

    if (isValid) {
      await this.api.saveTheForm(data);
      this.flashMessages.success('It worked');
      this.router.transitionTo('another.route');
    }
  } catch(error) {
    const { message } = await this.api.parseError(error);
    this.errorMessage = message;
  }
}