@webbycrown/advanced-fields 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -1
- package/dist/_chunks/{index-lJs3vGYF.js → index-AT-E0hrg.js} +0 -1
- package/dist/_chunks/{index-DTSlHlvg.mjs → index-cLPilu5W.mjs} +0 -1
- package/dist/admin/index.js +13 -1
- package/dist/admin/index.mjs +13 -1
- package/package.json +3 -8
- package/dist/admin/translations/en.json +0 -86
- package/index.js +0 -158
- package/strapi-server.js +0 -186
- package/strapi-server.mjs +0 -74
package/README.md
CHANGED
|
@@ -8,6 +8,16 @@ Professional custom fields for Strapi CMS that provide advanced functionality wi
|
|
|
8
8
|
|
|
9
9
|
📦 **NPM Package**: [@webbycrown/advanced-fields](https://www.npmjs.com/package/@webbycrown/advanced-fields)
|
|
10
10
|
|
|
11
|
+
## 🎥 Overview & Usage Demo
|
|
12
|
+
|
|
13
|
+
A short introduction and quick overview of **Advanced Fields for Strapi**, showcasing available field types, configuration options, and real-world usage inside the Strapi admin panel.
|
|
14
|
+
|
|
15
|
+
[](https://www.youtube.com/watch?v=-WRuUEWwGfk)
|
|
16
|
+
|
|
17
|
+
▶️ **[Watch Full Video on YouTube](https://www.youtube.com/watch?v=-WRuUEWwGfk)**
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
11
21
|
## ✨ Features
|
|
12
22
|
|
|
13
23
|
### 🔤 Advanced Input
|
|
@@ -57,6 +67,7 @@ yarn add @webbycrown/advanced-fields
|
|
|
57
67
|
- Advanced Checkbox
|
|
58
68
|
- Advanced Radio
|
|
59
69
|
|
|
70
|
+
|
|
60
71
|
## 📖 Usage Examples
|
|
61
72
|
|
|
62
73
|
### Advanced Input Configuration
|
|
@@ -263,8 +274,24 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
|
263
274
|
|
|
264
275
|
## 📊 Changelog
|
|
265
276
|
|
|
277
|
+
### v1.0.4
|
|
278
|
+
- 🐛 Fixed minor bugs in field validation
|
|
279
|
+
- 📝 Updated README to include Demo Video section
|
|
280
|
+
- ⚡ Improved documentation clarity for plugin setup and usage
|
|
281
|
+
|
|
282
|
+
### v1.0.3
|
|
283
|
+
- 📝 Documentation updates and minor formatting improvements.
|
|
284
|
+
|
|
285
|
+
### v1.0.2
|
|
286
|
+
- 🐛 Fixed bugs.
|
|
287
|
+
- 🛠️ Resolved minor issues affecting
|
|
288
|
+
|
|
289
|
+
### v1.0.1
|
|
290
|
+
- 📝 Updated the README file.
|
|
291
|
+
- ✨ Improved clarity and formatting for better readability.
|
|
292
|
+
|
|
266
293
|
### v1.0.0
|
|
267
|
-
- ✨ Initial release
|
|
294
|
+
- ✨ Initial release
|
|
268
295
|
- 🔤 Advanced Input field with validation
|
|
269
296
|
- ☑️ Advanced Checkbox (single/multiple)
|
|
270
297
|
- 🔘 Advanced Radio (single/multiple)
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const jsxRuntime = require("react/jsx-runtime");
|
|
4
4
|
const reactIntl = require("react-intl");
|
|
5
5
|
const designSystem = require("@strapi/design-system");
|
|
6
|
-
require("@strapi/icons");
|
|
7
6
|
const react = require("react");
|
|
8
7
|
const AdvancedInput = ({
|
|
9
8
|
attribute = {},
|
package/dist/admin/index.js
CHANGED
|
@@ -19,6 +19,9 @@ const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
|
|
|
19
19
|
});
|
|
20
20
|
};
|
|
21
21
|
const PLUGIN_ID = "advanced-fields";
|
|
22
|
+
const PluginIcon = (props) => {
|
|
23
|
+
return /* @__PURE__ */ jsxRuntime.jsx(AdvancedRadioIcon, { ...props });
|
|
24
|
+
};
|
|
22
25
|
const AdvancedInputIcon = () => /* @__PURE__ */ jsxRuntime.jsx(
|
|
23
26
|
designSystem.Box,
|
|
24
27
|
{
|
|
@@ -121,7 +124,7 @@ const customFields = [
|
|
|
121
124
|
type: "string",
|
|
122
125
|
icon: AdvancedInputIcon,
|
|
123
126
|
pluginId: PLUGIN_ID,
|
|
124
|
-
component: () => Promise.resolve().then(() => require("../_chunks/index-
|
|
127
|
+
component: () => Promise.resolve().then(() => require("../_chunks/index-AT-E0hrg.js")),
|
|
125
128
|
intlLabel: {
|
|
126
129
|
id: `${PLUGIN_ID}.input.label`,
|
|
127
130
|
defaultMessage: "Advanced Input"
|
|
@@ -795,6 +798,15 @@ const index = {
|
|
|
795
798
|
if (!app.customFields) {
|
|
796
799
|
return;
|
|
797
800
|
}
|
|
801
|
+
try {
|
|
802
|
+
app.registerPlugin({
|
|
803
|
+
id: PLUGIN_ID,
|
|
804
|
+
name: "Advanced Fields",
|
|
805
|
+
icon: PluginIcon,
|
|
806
|
+
isReady: true
|
|
807
|
+
});
|
|
808
|
+
} catch (e) {
|
|
809
|
+
}
|
|
798
810
|
customFields.forEach((field) => {
|
|
799
811
|
try {
|
|
800
812
|
app.customFields.register({
|
package/dist/admin/index.mjs
CHANGED
|
@@ -18,6 +18,9 @@ const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
|
|
|
18
18
|
});
|
|
19
19
|
};
|
|
20
20
|
const PLUGIN_ID = "advanced-fields";
|
|
21
|
+
const PluginIcon = (props) => {
|
|
22
|
+
return /* @__PURE__ */ jsx(AdvancedRadioIcon, { ...props });
|
|
23
|
+
};
|
|
21
24
|
const AdvancedInputIcon = () => /* @__PURE__ */ jsx(
|
|
22
25
|
Box,
|
|
23
26
|
{
|
|
@@ -120,7 +123,7 @@ const customFields = [
|
|
|
120
123
|
type: "string",
|
|
121
124
|
icon: AdvancedInputIcon,
|
|
122
125
|
pluginId: PLUGIN_ID,
|
|
123
|
-
component: () => import("../_chunks/index-
|
|
126
|
+
component: () => import("../_chunks/index-cLPilu5W.mjs"),
|
|
124
127
|
intlLabel: {
|
|
125
128
|
id: `${PLUGIN_ID}.input.label`,
|
|
126
129
|
defaultMessage: "Advanced Input"
|
|
@@ -794,6 +797,15 @@ const index = {
|
|
|
794
797
|
if (!app.customFields) {
|
|
795
798
|
return;
|
|
796
799
|
}
|
|
800
|
+
try {
|
|
801
|
+
app.registerPlugin({
|
|
802
|
+
id: PLUGIN_ID,
|
|
803
|
+
name: "Advanced Fields",
|
|
804
|
+
icon: PluginIcon,
|
|
805
|
+
isReady: true
|
|
806
|
+
});
|
|
807
|
+
} catch (e) {
|
|
808
|
+
}
|
|
797
809
|
customFields.forEach((field) => {
|
|
798
810
|
try {
|
|
799
811
|
app.customFields.register({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webbycrown/advanced-fields",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"strapi",
|
|
6
6
|
"plugin",
|
|
@@ -25,18 +25,13 @@
|
|
|
25
25
|
"./strapi-server": "./strapi-server.js"
|
|
26
26
|
},
|
|
27
27
|
"files": [
|
|
28
|
-
"dist
|
|
29
|
-
"strapi-server.js",
|
|
30
|
-
"strapi-server.mjs",
|
|
31
|
-
"index.js",
|
|
28
|
+
"dist",
|
|
32
29
|
"README.md",
|
|
33
30
|
"LICENSE"
|
|
34
31
|
],
|
|
35
32
|
"scripts": {
|
|
36
|
-
"build": "npm run build:admin
|
|
33
|
+
"build": "npm run build:admin",
|
|
37
34
|
"build:admin": "strapi-plugin build",
|
|
38
|
-
"copy:translations": "cp -r admin/src/translations dist/admin/",
|
|
39
|
-
"prepublishOnly": "npm run build",
|
|
40
35
|
"watch": "strapi-plugin watch",
|
|
41
36
|
"watch:link": "strapi-plugin watch:link",
|
|
42
37
|
"verify": "strapi-plugin verify"
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"advanced-fields.plugin.name": "Advanced Fields",
|
|
3
|
-
"advanced-fields.input.label": "Advanced Input",
|
|
4
|
-
"advanced-fields.input.description": "Professional-grade text input with comprehensive validation and advanced configuration options",
|
|
5
|
-
"advanced-fields.checkbox.label": "Advanced Checkbox",
|
|
6
|
-
"advanced-fields.checkbox.description": "Unified checkbox field supporting both single and multiple selections with advanced configuration",
|
|
7
|
-
"advanced-fields.selectinput.label": "Select Input",
|
|
8
|
-
"advanced-fields.selectinput.description": "Select an option",
|
|
9
|
-
|
|
10
|
-
"advanced-fields.input.settings.base.label": "Basic settings",
|
|
11
|
-
"advanced-fields.input.options.required.label": "Required field",
|
|
12
|
-
"advanced-fields.input.options.required.description": "You won't be able to create an entry if this field is empty",
|
|
13
|
-
"advanced-fields.input.options.unique.label": "Unique field",
|
|
14
|
-
"advanced-fields.input.options.unique.description": "You won't be able to create an entry if there is an existing entry with identical content",
|
|
15
|
-
"advanced-fields.input.options.maxLength.label": "Maximum length",
|
|
16
|
-
"advanced-fields.input.options.maxLength.description": "Set the maximum number of characters allowed",
|
|
17
|
-
"advanced-fields.input.options.minLength.label": "Minimum length",
|
|
18
|
-
"advanced-fields.input.options.minLength.description": "Set the minimum number of characters allowed",
|
|
19
|
-
"advanced-fields.input.options.defaultValue.label": "Default value",
|
|
20
|
-
"advanced-fields.input.options.defaultValue.description": "Set the default value for this field",
|
|
21
|
-
|
|
22
|
-
"advanced-fields.input.settings.advanced.label": "Advanced settings",
|
|
23
|
-
"advanced-fields.input.options.regex.label": "RegExp pattern",
|
|
24
|
-
"advanced-fields.input.options.regex.description": "The text of the regular expression",
|
|
25
|
-
"advanced-fields.input.options.placeholder.label": "Placeholder",
|
|
26
|
-
"advanced-fields.input.options.placeholder.description": "Display text when the field is empty",
|
|
27
|
-
"advanced-fields.input.options.private.label": "Private field",
|
|
28
|
-
"advanced-fields.input.options.private.description": "This field will not be included in API responses",
|
|
29
|
-
"advanced-fields.input.options.customErrorMessage.label": "Custom error message",
|
|
30
|
-
"advanced-fields.input.options.customErrorMessage.description": "Display a custom error message when validation fails",
|
|
31
|
-
|
|
32
|
-
"advanced-fields.checkbox.settings.base.label": "Basic settings",
|
|
33
|
-
"advanced-fields.checkbox.options.required.label": "Required field",
|
|
34
|
-
"advanced-fields.checkbox.options.required.description": "You won't be able to create an entry if this field is empty",
|
|
35
|
-
"advanced-fields.checkbox.options.checkboxType.label": "Checkbox Type",
|
|
36
|
-
"advanced-fields.checkbox.options.checkboxType.description": "Choose between single checkbox or multiple checkboxes",
|
|
37
|
-
"advanced-fields.checkbox.options.checkboxType.single": "Single Checkbox",
|
|
38
|
-
"advanced-fields.checkbox.options.checkboxType.multiple": "Multiple Checkboxes",
|
|
39
|
-
"advanced-fields.checkbox.options.defaultValue.label": "Default State",
|
|
40
|
-
"advanced-fields.checkbox.options.defaultValue.description": "Pre-checked state for single checkbox",
|
|
41
|
-
"advanced-fields.checkbox.options.defaultValue.options.true": "Checked (True)",
|
|
42
|
-
"advanced-fields.checkbox.options.defaultValue.options.false": "Unchecked (False)",
|
|
43
|
-
|
|
44
|
-
"advanced-fields.checkbox.settings.advanced.label": "Advanced settings",
|
|
45
|
-
"advanced-fields.checkbox.options.customErrorMessage.label": "Custom error message",
|
|
46
|
-
"advanced-fields.checkbox.options.customErrorMessage.description": "Display a custom error message when validation fails",
|
|
47
|
-
"advanced-fields.checkbox.options.customErrorMessage.placeholder": "Enter custom error message",
|
|
48
|
-
"advanced-fields.checkbox.options.private.label": "Private field",
|
|
49
|
-
"advanced-fields.checkbox.options.private.description": "This field will not be included in API responses",
|
|
50
|
-
"advanced-fields.checkbox.options.labelOn.label": "Checked Label",
|
|
51
|
-
"advanced-fields.checkbox.options.labelOn.description": "Custom label displayed when single checkbox is checked",
|
|
52
|
-
"advanced-fields.checkbox.options.labelOff.label": "Unchecked Label",
|
|
53
|
-
"advanced-fields.checkbox.options.labelOff.description": "Custom label displayed when single checkbox is unchecked",
|
|
54
|
-
"advanced-fields.checkbox.options.checkboxOptions.label": "Checkbox Options",
|
|
55
|
-
"advanced-fields.checkbox.options.checkboxOptions.description": "Define available options for multiple checkboxes (one per line: value|label)",
|
|
56
|
-
"advanced-fields.checkbox.options.checkboxOptions.placeholder": "option1|Option 1\noption2|Option 2\noption3|Option 3",
|
|
57
|
-
"advanced-fields.checkbox.options.defaultSelected.label": "Default Selected",
|
|
58
|
-
"advanced-fields.checkbox.options.defaultSelected.description": "Pre-selected options for multiple checkboxes (one per line)",
|
|
59
|
-
"advanced-fields.checkbox.options.defaultSelected.placeholder": "option1\noption2",
|
|
60
|
-
"advanced-fields.checkbox.options.minChoices.label": "Minimum Choices",
|
|
61
|
-
"advanced-fields.checkbox.options.minChoices.description": "Minimum number of options that must be selected (0 for no minimum)",
|
|
62
|
-
"advanced-fields.checkbox.options.maxChoices.label": "Maximum Choices",
|
|
63
|
-
"advanced-fields.checkbox.options.maxChoices.description": "Maximum number of options that can be selected (0 for no maximum)",
|
|
64
|
-
"advanced-fields.checkbox.options.layout.label": "Layout Style",
|
|
65
|
-
"advanced-fields.checkbox.options.layout.description": "Visual layout of multiple checkbox options",
|
|
66
|
-
"advanced-fields.checkbox.options.layout.vertical": "Vertical Stack",
|
|
67
|
-
"advanced-fields.checkbox.options.layout.horizontal": "Horizontal Row",
|
|
68
|
-
"advanced-fields.checkbox.options.layout.grid": "Grid Layout",
|
|
69
|
-
|
|
70
|
-
"advanced-fields.radio.label": "Multiple Type Choice",
|
|
71
|
-
"advanced-fields.radio.description": "Select one or more options (radio style)",
|
|
72
|
-
"advanced-fields.radio.settings.base.label": "Basic settings",
|
|
73
|
-
"advanced-fields.radio.options.required.label": "Multiple Type Choice",
|
|
74
|
-
"advanced-fields.radio.options.required.description": "You won't be able to create an entry if this field is empty",
|
|
75
|
-
"advanced-fields.radio.options.radioOptions.label": "Multiple Type Choice",
|
|
76
|
-
"advanced-fields.radio.options.radioOptions.description": "Enter one option per line in format: value|label (e.g., \"1|Option 1\")",
|
|
77
|
-
"advanced-fields.radio.options.radioOptions.placeholder": "1|Option 1\n2|Option 2\n3|Option 3",
|
|
78
|
-
"advanced-fields.radio.options.selectionType.label": "Selection Type",
|
|
79
|
-
"advanced-fields.radio.options.selectionType.description": "Allow selecting only one or multiple type choices",
|
|
80
|
-
"advanced-fields.radio.options.customErrorMessage.label": "Custom error message",
|
|
81
|
-
"advanced-fields.radio.options.customErrorMessage.description": "Display a custom error message when validation fails",
|
|
82
|
-
"advanced-fields.radio.options.customErrorMessage.placeholder": "Enter custom error message",
|
|
83
|
-
"advanced-fields.radio.no-options": "No options defined. Please configure this field in the content type settings.",
|
|
84
|
-
"advanced-fields.radio.options.type.single": "Single selection",
|
|
85
|
-
"advanced-fields.radio.options.type.multiple": "Multiple selection"
|
|
86
|
-
}
|
package/index.js
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const PLUGIN_ID = 'advanced-fields';
|
|
4
|
-
|
|
5
|
-
const customFields = [
|
|
6
|
-
{
|
|
7
|
-
name: 'input',
|
|
8
|
-
type: 'string',
|
|
9
|
-
validate: (value, { required, options = {} }) => {
|
|
10
|
-
// Basic required validation
|
|
11
|
-
if (required && (!value || value.toString().trim().length === 0)) {
|
|
12
|
-
return 'This field is required';
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// Length validation
|
|
16
|
-
if (value && options.maxLength && value.length > options.maxLength) {
|
|
17
|
-
return `Maximum length is ${options.maxLength} characters`;
|
|
18
|
-
}
|
|
19
|
-
if (value && options.minLength && value.length < options.minLength) {
|
|
20
|
-
return `Minimum length is ${options.minLength} characters`;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Regex validation
|
|
24
|
-
if (value && options.regex) {
|
|
25
|
-
try {
|
|
26
|
-
const regex = new RegExp(options.regex);
|
|
27
|
-
if (!regex.test(value)) {
|
|
28
|
-
return options.customErrorMessage || 'Value does not match required format';
|
|
29
|
-
}
|
|
30
|
-
} catch (e) {
|
|
31
|
-
// Invalid regex pattern - silently ignore
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Input type validation
|
|
36
|
-
if (value && options.inputType) {
|
|
37
|
-
switch (options.inputType) {
|
|
38
|
-
case 'email':
|
|
39
|
-
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
40
|
-
if (!emailRegex.test(value)) {
|
|
41
|
-
return 'Please enter a valid email address';
|
|
42
|
-
}
|
|
43
|
-
break;
|
|
44
|
-
case 'url':
|
|
45
|
-
try {
|
|
46
|
-
new URL(value);
|
|
47
|
-
} catch {
|
|
48
|
-
return 'Please enter a valid URL';
|
|
49
|
-
}
|
|
50
|
-
break;
|
|
51
|
-
case 'number':
|
|
52
|
-
if (isNaN(parseFloat(value))) {
|
|
53
|
-
return 'Please enter a valid number';
|
|
54
|
-
}
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
name: 'checkbox',
|
|
64
|
-
type: 'json',
|
|
65
|
-
validate: (value, { required, options = {} }) => {
|
|
66
|
-
|
|
67
|
-
// Basic required validation
|
|
68
|
-
if (required) {
|
|
69
|
-
if (!value ||
|
|
70
|
-
(Array.isArray(value) && value.length === 0) ||
|
|
71
|
-
(typeof value === 'string' && value.trim() === '') ||
|
|
72
|
-
value === null ||
|
|
73
|
-
value === undefined) {
|
|
74
|
-
return options.customErrorMessage || 'This field is required';
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// If no value and not required, no additional validation needed
|
|
79
|
-
if (!required && (!value || (Array.isArray(value) && value.length === 0))) {
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Choice validation for multiple checkboxes only
|
|
84
|
-
if (options.checkboxType === 'multiple' && Array.isArray(value)) {
|
|
85
|
-
if (options.minChoices > 0 && value.length < options.minChoices) {
|
|
86
|
-
return options.customErrorMessage || `Please select at least ${options.minChoices} option${options.minChoices > 1 ? 's' : ''}`;
|
|
87
|
-
}
|
|
88
|
-
if (options.maxChoices > 0 && value.length > options.maxChoices) {
|
|
89
|
-
return options.customErrorMessage || `Please select at most ${options.maxChoices} option${options.maxChoices > 1 ? 's' : ''}`;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
name: "radio",
|
|
98
|
-
type: "json",
|
|
99
|
-
validate: (value, { required, options = {} }) => {
|
|
100
|
-
// Basic required validation
|
|
101
|
-
if (required) {
|
|
102
|
-
if (!value ||
|
|
103
|
-
(Array.isArray(value) && value.length === 0) ||
|
|
104
|
-
(typeof value === 'string' && value.trim() === '') ||
|
|
105
|
-
value === null ||
|
|
106
|
-
value === undefined) {
|
|
107
|
-
return 'This field is required';
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// Choice validation
|
|
112
|
-
if (Array.isArray(value)) {
|
|
113
|
-
if (options.minChoices > 0 && value.length < options.minChoices) {
|
|
114
|
-
return `Please select at least ${options.minChoices} option${options.minChoices > 1 ? 's' : ''}`;
|
|
115
|
-
}
|
|
116
|
-
if (options.maxChoices > 0 && value.length > options.maxChoices) {
|
|
117
|
-
return `Please select at most ${options.maxChoices} option${options.maxChoices > 1 ? 's' : ''}`;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return null;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
];
|
|
125
|
-
|
|
126
|
-
module.exports = {
|
|
127
|
-
register({ strapi }) {
|
|
128
|
-
// Ensure custom fields registry is available
|
|
129
|
-
if (!strapi.customFields) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// Register custom fields with proper error handling
|
|
134
|
-
customFields.forEach((field) => {
|
|
135
|
-
try {
|
|
136
|
-
|
|
137
|
-
const fieldConfig = {
|
|
138
|
-
name: field.name,
|
|
139
|
-
pluginId: PLUGIN_ID,
|
|
140
|
-
type: field.type,
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
// Add validation function if it exists
|
|
144
|
-
if (field.validate) {
|
|
145
|
-
fieldConfig.validate = field.validate;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
strapi.customFields.register(fieldConfig);
|
|
149
|
-
} catch (error) {
|
|
150
|
-
// Field registration failed - silently continue
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
},
|
|
154
|
-
|
|
155
|
-
bootstrap({ strapi }) {
|
|
156
|
-
// Bootstrap completed
|
|
157
|
-
},
|
|
158
|
-
};
|
package/strapi-server.js
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const PLUGIN_ID = 'advanced-fields';
|
|
4
|
-
|
|
5
|
-
const customFields = [
|
|
6
|
-
{
|
|
7
|
-
name: 'input',
|
|
8
|
-
type: 'string',
|
|
9
|
-
validate: (value, { required, options = {} }) => {
|
|
10
|
-
// Parse field options
|
|
11
|
-
const {
|
|
12
|
-
minLength = 0,
|
|
13
|
-
maxLength = 0,
|
|
14
|
-
regex = '',
|
|
15
|
-
customErrorMessage = ''
|
|
16
|
-
} = options;
|
|
17
|
-
|
|
18
|
-
// Check required validation
|
|
19
|
-
if (required && (!value || value.trim().length === 0)) {
|
|
20
|
-
return customErrorMessage || 'This field is required';
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// If no value, no additional validation needed
|
|
24
|
-
if (!value || value.trim().length === 0) {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const stringValue = value.toString().trim();
|
|
29
|
-
|
|
30
|
-
// Check min/max length validation
|
|
31
|
-
if (minLength > 0 && stringValue.length < minLength) {
|
|
32
|
-
return customErrorMessage || `Minimum length is ${minLength} characters`;
|
|
33
|
-
}
|
|
34
|
-
if (maxLength > 0 && stringValue.length > maxLength) {
|
|
35
|
-
return customErrorMessage || `Maximum length is ${maxLength} characters`;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Check regex validation
|
|
39
|
-
if (regex && regex.trim()) {
|
|
40
|
-
try {
|
|
41
|
-
const regexPattern = new RegExp(regex);
|
|
42
|
-
if (!regexPattern.test(stringValue)) {
|
|
43
|
-
return customErrorMessage || 'Value does not match the required pattern';
|
|
44
|
-
}
|
|
45
|
-
} catch (e) {
|
|
46
|
-
// Invalid regex pattern, skip validation
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
name: 'checkbox',
|
|
55
|
-
type: 'json',
|
|
56
|
-
validate: (value, { required, options = {} }) => {
|
|
57
|
-
// Parse field options
|
|
58
|
-
const {
|
|
59
|
-
checkboxType = 'single',
|
|
60
|
-
minChoices = 0,
|
|
61
|
-
maxChoices = 0,
|
|
62
|
-
customErrorMessage = ''
|
|
63
|
-
} = options;
|
|
64
|
-
|
|
65
|
-
// Check required validation
|
|
66
|
-
if (required) {
|
|
67
|
-
if (!value ||
|
|
68
|
-
(Array.isArray(value) && value.length === 0) ||
|
|
69
|
-
(typeof value === 'string' && value.trim() === '') ||
|
|
70
|
-
value === null ||
|
|
71
|
-
value === undefined) {
|
|
72
|
-
return customErrorMessage || 'This field is required';
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// If no value, no additional validation needed
|
|
77
|
-
if (!value || (Array.isArray(value) && value.length === 0)) {
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const values = Array.isArray(value) ? value : [];
|
|
82
|
-
|
|
83
|
-
// Check min/max choices validation (only for multiple mode)
|
|
84
|
-
if (checkboxType === 'multiple') {
|
|
85
|
-
if (minChoices > 0 && values.length < minChoices) {
|
|
86
|
-
return customErrorMessage || `Please select at least ${minChoices} option${minChoices > 1 ? 's' : ''}`;
|
|
87
|
-
}
|
|
88
|
-
if (maxChoices > 0 && values.length > maxChoices) {
|
|
89
|
-
return customErrorMessage || `Please select at most ${maxChoices} option${maxChoices > 1 ? 's' : ''}`;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
name: "radio",
|
|
98
|
-
type: "json",
|
|
99
|
-
validate: (value, { required, options = {} }) => {
|
|
100
|
-
// Parse field options
|
|
101
|
-
const {
|
|
102
|
-
selectionType = 'single',
|
|
103
|
-
minChoices = 0,
|
|
104
|
-
maxChoices = 0,
|
|
105
|
-
customErrorMessage = ''
|
|
106
|
-
} = options;
|
|
107
|
-
|
|
108
|
-
// Check required validation
|
|
109
|
-
if (required) {
|
|
110
|
-
if (!value ||
|
|
111
|
-
(Array.isArray(value) && value.length === 0) ||
|
|
112
|
-
(typeof value === 'string' && value.trim() === '') ||
|
|
113
|
-
value === null ||
|
|
114
|
-
value === undefined) {
|
|
115
|
-
return customErrorMessage || 'This field is required';
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// If no value, no additional validation needed
|
|
120
|
-
if (!value || (Array.isArray(value) && value.length === 0)) {
|
|
121
|
-
return null;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const values = Array.isArray(value) ? value : [];
|
|
125
|
-
|
|
126
|
-
// Check min/max choices validation (only for multiple mode)
|
|
127
|
-
if (selectionType === 'multiple') {
|
|
128
|
-
if (minChoices > 0 && values.length < minChoices) {
|
|
129
|
-
return customErrorMessage || `Please select at least ${minChoices} option${minChoices > 1 ? 's' : ''}`;
|
|
130
|
-
}
|
|
131
|
-
if (maxChoices > 0 && values.length > maxChoices) {
|
|
132
|
-
return customErrorMessage || `Please select at most ${maxChoices} option${maxChoices > 1 ? 's' : ''}`;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return null;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
];
|
|
140
|
-
|
|
141
|
-
module.exports = {
|
|
142
|
-
register({ strapi }) {
|
|
143
|
-
// Ensure custom fields registry is available
|
|
144
|
-
if (!strapi.customFields) {
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// Register custom fields with proper error handling
|
|
149
|
-
customFields.forEach((field) => {
|
|
150
|
-
try {
|
|
151
|
-
const fieldConfig = {
|
|
152
|
-
name: field.name,
|
|
153
|
-
plugin: PLUGIN_ID,
|
|
154
|
-
type: field.type,
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
// Add validation function if it exists
|
|
158
|
-
if (field.validate) {
|
|
159
|
-
fieldConfig.validate = field.validate;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
strapi.customFields.register(fieldConfig);
|
|
163
|
-
} catch (error) {
|
|
164
|
-
// Silent error handling
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
},
|
|
168
|
-
|
|
169
|
-
bootstrap({ strapi }) {
|
|
170
|
-
// Wait longer for registration to complete
|
|
171
|
-
setTimeout(() => {
|
|
172
|
-
// Verify all fields are registered only if customFields.get is available
|
|
173
|
-
if (strapi.customFields && typeof strapi.customFields.get === 'function') {
|
|
174
|
-
customFields.forEach((field) => {
|
|
175
|
-
try {
|
|
176
|
-
const registeredField = strapi.customFields.get(`${PLUGIN_ID}.${field.name}`);
|
|
177
|
-
// Field verification completed silently
|
|
178
|
-
} catch (error) {
|
|
179
|
-
// Silent error handling
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
}, 1000);
|
|
184
|
-
},
|
|
185
|
-
};
|
|
186
|
-
|
package/strapi-server.mjs
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const PLUGIN_ID = 'advanced-fields';
|
|
4
|
-
|
|
5
|
-
const customFields = [
|
|
6
|
-
{
|
|
7
|
-
name: 'input',
|
|
8
|
-
type: 'string',
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
name: 'checkbox',
|
|
12
|
-
type: 'json',
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
name: "radio",
|
|
16
|
-
type: "json"
|
|
17
|
-
}
|
|
18
|
-
];
|
|
19
|
-
|
|
20
|
-
module.exports = {
|
|
21
|
-
register({ strapi }) {
|
|
22
|
-
console.log(`[${PLUGIN_ID}] Registering custom fields...`);
|
|
23
|
-
|
|
24
|
-
// Ensure custom fields registry is available
|
|
25
|
-
if (!strapi.customFields) {
|
|
26
|
-
console.error(`[${PLUGIN_ID}] Custom fields registry not available`);
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Register custom fields with proper error handling
|
|
31
|
-
customFields.forEach((field) => {
|
|
32
|
-
try {
|
|
33
|
-
console.log(`[${PLUGIN_ID}] Registering field: ${field.name} (type: ${field.type})`);
|
|
34
|
-
strapi.customFields.register({
|
|
35
|
-
name: field.name,
|
|
36
|
-
plugin: PLUGIN_ID,
|
|
37
|
-
type: field.type,
|
|
38
|
-
});
|
|
39
|
-
console.log(`[${PLUGIN_ID}] Successfully registered field: ${field.name}`);
|
|
40
|
-
} catch (error) {
|
|
41
|
-
console.error(`[${PLUGIN_ID}] Failed to register field ${field.name}:`, error.message);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
console.log(`[${PLUGIN_ID}] All custom fields registration completed`);
|
|
46
|
-
},
|
|
47
|
-
|
|
48
|
-
bootstrap({ strapi }) {
|
|
49
|
-
console.log(`[${PLUGIN_ID}] Bootstrap starting...`);
|
|
50
|
-
|
|
51
|
-
// Wait longer for registration to complete
|
|
52
|
-
setTimeout(() => {
|
|
53
|
-
// Verify all fields are registered only if customFields.get is available
|
|
54
|
-
if (strapi.customFields && typeof strapi.customFields.get === 'function') {
|
|
55
|
-
customFields.forEach((field) => {
|
|
56
|
-
try {
|
|
57
|
-
const registeredField = strapi.customFields.get(`${PLUGIN_ID}.${field.name}`);
|
|
58
|
-
if (registeredField) {
|
|
59
|
-
console.log(`[${PLUGIN_ID}] ✅ Field verified: ${field.name}`);
|
|
60
|
-
} else {
|
|
61
|
-
console.error(`[${PLUGIN_ID}] ❌ Field not found in registry: ${field.name}`);
|
|
62
|
-
}
|
|
63
|
-
} catch (error) {
|
|
64
|
-
console.error(`[${PLUGIN_ID}] Error verifying field ${field.name}:`, error.message);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
} else {
|
|
68
|
-
console.log(`[${PLUGIN_ID}] Skipping field verification (customFields.get not available)`);
|
|
69
|
-
}
|
|
70
|
-
}, 1000);
|
|
71
|
-
|
|
72
|
-
console.log(`[${PLUGIN_ID}] Bootstrap completed`);
|
|
73
|
-
},
|
|
74
|
-
};
|