@@ -25,9 +32,37 @@
{% block form %}
{% if page.allowContinue %}
- {% include "partials/form.html" %}
+
{% else %}
- {{ componentList(components) }}
+ {% block nonFormComponents %}
+ {{ componentList(components) }}
+ {% endblock %}
{% endif %}
{% endblock %}
diff --git a/src/server/plugins/engine/views/partials/form.html b/src/server/plugins/engine/views/partials/form.html
index fb3476725..36eedf704 100644
--- a/src/server/plugins/engine/views/partials/form.html
+++ b/src/server/plugins/engine/views/partials/form.html
@@ -4,23 +4,27 @@
diff --git a/src/server/plugins/nunjucks/types.js b/src/server/plugins/nunjucks/types.js
index 2ad7ad3d7..530ea3b70 100644
--- a/src/server/plugins/nunjucks/types.js
+++ b/src/server/plugins/nunjucks/types.js
@@ -17,6 +17,7 @@
* @property {string} [currentPath] - Current path
* @property {string} [previewMode] - Preview mode
* @property {string} [slug] - Form slug
+ * @property {object[]} [buttons] - Button override
* @property {FormContext} [context] - the current form context
*/
diff --git a/src/server/schemas/index.ts b/src/server/schemas/index.ts
index 38006860c..4ff6824f3 100644
--- a/src/server/schemas/index.ts
+++ b/src/server/schemas/index.ts
@@ -7,7 +7,7 @@ export const stateSchema = Joi.string
()
.valid(FormStatus.Draft, FormStatus.Live)
.required()
-export const actionSchema = Joi.string()
+const actionSchema = Joi.string()
.valid(
FormAction.Continue,
FormAction.Validate,
@@ -24,7 +24,7 @@ export const itemIdSchema = Joi.string().uuid().required()
export const crumbSchema = Joi.string().optional().allow('')
export const confirmSchema = Joi.boolean().empty(false)
-export const paramsSchema = Joi.object()
+const paramsSchema = Joi.object()
.keys({
action: actionSchema,
confirm: confirmSchema,
@@ -33,3 +33,13 @@ export const paramsSchema = Joi.object()
})
.default({})
.optional()
+
+export function buildActionSchema(customActions: string[]) {
+ return actionSchema.valid(...customActions)
+}
+
+export function buildParamsSchema(customActions: string[]) {
+ return paramsSchema.alter({
+ action: (schema) => schema.valid(...customActions)
+ })
+}
diff --git a/src/typings/hapi/index.d.ts b/src/typings/hapi/index.d.ts
index 8067b4e43..0852e8acb 100644
--- a/src/typings/hapi/index.d.ts
+++ b/src/typings/hapi/index.d.ts
@@ -2,11 +2,13 @@
import { type Plugin } from '@hapi/hapi'
import { type ServerYar, type Yar } from '@hapi/yar'
+import { type Schema as JoiSchema } from 'joi'
import { type Logger } from 'pino'
import { type FormModel } from '~/src/server/plugins/engine/models/index.js'
import { type PluginOptions } from '~/src/server/plugins/engine/types.ts'
import {
+ type FormAction,
type FormRequest,
type FormRequestPayload
} from '~/src/server/routes/types.js'
@@ -26,6 +28,19 @@ declare module '@hapi/hapi' {
request: FormRequest | FormRequestPayload | null
) => Record | Promise>
saveAndReturn?: PluginOptions['saveAndReturn']
+ buttons?: {
+ text: string
+ name?: string
+ action?: string
+ }[]
+ actionHandlers: Record<
+ FormAction | string,
+ (request: FormRequestPayload, context: FormContext) => Promise
+ >
+ schemas: {
+ actionSchema: JoiSchema
+ paramsSchema: JoiSchema
+ }
}
}