diff --git a/src/action.ts b/src/action.ts index c17e75e..8282672 100644 --- a/src/action.ts +++ b/src/action.ts @@ -38,7 +38,6 @@ export interface ActionInfo { * Returns the list of fields associated to an action */ fields: Field[]; - } /** @@ -51,6 +50,10 @@ export interface Action = Record> ext */ submit(formData: T): Promise; + /** + * Return a field by name. + */ + field(name: string): Field | undefined; } export class SimpleAction> implements Action { @@ -157,6 +160,10 @@ export class SimpleAction> implements Acti return state; } + + field(name: string): Field | undefined { + return this.fields.find(field => field.name === name); + } } export class ActionNotFound extends Error {} diff --git a/test/unit/state/hal-forms.ts b/test/unit/state/hal-forms.ts index 8495950..e4110c3 100644 --- a/test/unit/state/hal-forms.ts +++ b/test/unit/state/hal-forms.ts @@ -3,7 +3,7 @@ import { factory } from '../../../src/state/hal'; import { Action, Client, Field } from '../../../src'; import { HalFormsProperty } from 'hal-types'; -type CompareAction = Omit; +type CompareAction = Omit; describe('HAL forms', () => {