Skip to content

Commit

Permalink
feature/dg-add-subscription-hidden-field: use subscription hidden fie…
Browse files Browse the repository at this point in the history
…ld in the hidden field widget
  • Loading branch information
dawgoc committed Aug 21, 2023
1 parent d021238 commit 5692255
Showing 1 changed file with 51 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,42 @@
import * as Scrivito from "scrivito";
import formHiddenFieldWidgetIcon from "../../assets/images/form_hidden_field_widget.svg";
import { customFieldNameValidation } from "../FormContainerWidget/utils/validations/customFieldNameValidation";
import { isCustomType } from "../FormContainerWidget/utils/isCustomType";
import { typeValidation } from "../FormContainerWidget/utils/validations/typeValidation";
import { getFieldName } from "../FormContainerWidget/utils/getFieldName";

Scrivito.provideEditingConfig("FormHiddenFieldWidget", {
title: "Hidden Form Field",
thumbnail: formHiddenFieldWidgetIcon,
attributes: {
type: {
title: "Input type",
values: [
{ value: "custom", title: "Custom" },
...(process.env.ENABLE_NEOLETTER_FORM_BUILDER_SUBSCRIPTION_FEATURE
? [{ value: "subscription", title: "Subscription" }]
: []),
],
},
customFieldName: { title: "Field name" },
hiddenValue: {
title: "Hidden value",
description: "This value is sent on every submission of the form.",
},
},
properties: ["customFieldName", "hiddenValue"],
properties: (widget) => {
if (process.env.ENABLE_NEOLETTER_FORM_BUILDER_SUBSCRIPTION_FEATURE) {
if (!isCustomType(widget)) {
return ["type", "hiddenValue"];
}

return ["type", "customFieldName", "hiddenValue"];
}

return ["customFieldName", "hiddenValue"];
},
initialContent: {
type: "custom",
customFieldName: "custom_hidden_field",
},
validations: [
Expand All @@ -34,12 +57,32 @@ Scrivito.provideEditingConfig("FormHiddenFieldWidget", {
severity: "info",
};
},
],
titleForContent: (widget) =>
`Hidden Form Field: ${[
widget.get("customFieldName"),
widget.get("hiddenValue"),
]
].concat(
process.env.ENABLE_NEOLETTER_FORM_BUILDER_SUBSCRIPTION_FEATURE
? [
typeValidation,
[
"hiddenValue",
(hiddenValue, { widget }) => {
const fieldName = getFieldName(widget);

if (fieldName === "subscription" && hiddenValue !== "on") {
return {
message:
"Please enter 'on' to activate the subscription process on every submission.",
severity: "warning",
};
}
},
],
]
: []
),
titleForContent: (widget) => {
const fieldName = getFieldName(widget);

return `Hidden Form Field: ${[fieldName, widget.get("hiddenValue")]
.filter((e) => e)
.join(" - ")}`,
.join(" - ")}`;
},
});

0 comments on commit 5692255

Please sign in to comment.