Skip to content

Commit

Permalink
Merge pull request #690 from DEFRA/feature/497169-forms-model-changes…
Browse files Browse the repository at this point in the history
…-for-page-events

Add Page Events to the FormDefinition
  • Loading branch information
davidjamesstone authored Jan 29, 2025
2 parents eb5407e + e10df23 commit dd56eb3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
22 changes: 21 additions & 1 deletion model/src/form/form-definition/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import {
} from '~/src/conditions/types.js'
import {
type ConditionWrapper,
type Event,
type EventOptions,
type Events,
type FormDefinition,
type Item,
type Link,
Expand Down Expand Up @@ -158,6 +161,21 @@ const pageRepeatSchema = Joi.object<Repeat>().keys({
schema: repeatSchema.required()
})

const eventSchema = Joi.object<Event>().keys({
type: Joi.string().allow('http').required(),
options: Joi.object<EventOptions>().keys({
method: Joi.string().allow('POST').required(),
url: Joi.string()
.uri({ scheme: ['http', 'https'] })
.required()
})
})

const eventsSchema = Joi.object<Events>().keys({
onLoad: eventSchema,
onSave: eventSchema
})

/**
* `/status` is a special route for providing a user's application status.
* It should not be configured via the designer.
Expand All @@ -174,7 +192,9 @@ const pageSchema = Joi.object<Page>().keys({
otherwise: Joi.any().strip()
}),
condition: Joi.string().allow('').optional(),
next: Joi.array<Link>().items(nextSchema)
next: Joi.array<Link>().items(nextSchema),
events: eventsSchema.optional(),
view: Joi.string().optional()
})

const baseListItemSchema = Joi.object<Item>().keys({
Expand Down
17 changes: 17 additions & 0 deletions model/src/form/form-definition/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,27 @@ export interface Link {
redirect?: string
}

export interface EventOptions {
method: string
url: string
}

export interface Event {
type: string
options: EventOptions
}

export interface Events {
onLoad: Event
onSave: Event
}

export interface PageBase {
title: string
path: string
condition?: string
events?: Events
view?: string
}

export interface RepeatOptions {
Expand Down

0 comments on commit dd56eb3

Please sign in to comment.