mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 10:31:15 +00:00
feat: Checkboxes and Radio Buttons field types (#17934)
Co-authored-by: Your Name <you@example.com> Co-authored-by: Roman Davydchuk <roman.davydchuk@n8n.io>
This commit is contained in:
@@ -22,7 +22,7 @@ import { getResolvables } from '../../../utils/utilities';
|
||||
import { WebhookAuthorizationError } from '../../Webhook/error';
|
||||
import { validateWebhookAuthentication } from '../../Webhook/utils';
|
||||
import { FORM_TRIGGER_AUTHENTICATION_PROPERTY } from '../interfaces';
|
||||
import type { FormTriggerData, FormTriggerInput } from '../interfaces';
|
||||
import type { FormTriggerData, FormField } from '../interfaces';
|
||||
|
||||
export function sanitizeHtml(text: string) {
|
||||
return sanitize(text, {
|
||||
@@ -187,7 +187,7 @@ export function prepareFormData({
|
||||
for (const [index, field] of formFields.entries()) {
|
||||
const { fieldType, requiredField, multiselect, placeholder } = field;
|
||||
|
||||
const input: IDataObject = {
|
||||
const input: FormField = {
|
||||
id: `field-${index}`,
|
||||
errorId: `error-field-${index}`,
|
||||
label: field.fieldLabel,
|
||||
@@ -196,13 +196,22 @@ export function prepareFormData({
|
||||
placeholder,
|
||||
};
|
||||
|
||||
if (multiselect) {
|
||||
if (multiselect || (fieldType && ['radio', 'checkbox'].includes(fieldType))) {
|
||||
input.isMultiSelect = true;
|
||||
input.multiSelectOptions =
|
||||
field.fieldOptions?.values.map((e, i) => ({
|
||||
id: `option${i}_${input.id}`,
|
||||
label: e.option,
|
||||
})) ?? [];
|
||||
|
||||
if (fieldType === 'radio') {
|
||||
input.radioSelect = 'radio';
|
||||
} else if (field.limitSelection === 'exact') {
|
||||
input.exactSelectedOptions = field.numberOfSelections;
|
||||
} else if (field.limitSelection === 'range') {
|
||||
input.minSelectedOptions = field.minSelections;
|
||||
input.maxSelectedOptions = field.maxSelections;
|
||||
}
|
||||
} else if (fieldType === 'file') {
|
||||
input.isFileInput = true;
|
||||
input.acceptFileTypes = field.acceptFileTypes;
|
||||
@@ -226,7 +235,7 @@ export function prepareFormData({
|
||||
input.type = fieldType as 'text' | 'number' | 'date' | 'email';
|
||||
}
|
||||
|
||||
formData.formFields.push(input as FormTriggerInput);
|
||||
formData.formFields.push(input);
|
||||
}
|
||||
|
||||
return formData;
|
||||
@@ -305,8 +314,15 @@ export function addFormResponseDataToReturnItem(
|
||||
if (field.fieldType === 'text') {
|
||||
value = String(value).trim();
|
||||
}
|
||||
if (field.multiselect && typeof value === 'string') {
|
||||
if (
|
||||
(field.multiselect || field.fieldType === 'checkbox' || field.fieldType === 'radio') &&
|
||||
typeof value === 'string'
|
||||
) {
|
||||
value = jsonParse(value);
|
||||
|
||||
if (field.fieldType === 'radio' && Array.isArray(value)) {
|
||||
value = value[0];
|
||||
}
|
||||
}
|
||||
if (field.fieldType === 'date' && value && field.formatDate !== '') {
|
||||
value = DateTime.fromFormat(String(value), 'yyyy-mm-dd').toFormat(field.formatDate as string);
|
||||
|
||||
Reference in New Issue
Block a user