fix(n8n Form Node): Resolve expressions in HTML fields (#13755)

This commit is contained in:
Michael Kret
2025-03-11 05:40:58 +02:00
committed by GitHub
parent 4fe249580a
commit de23ae5558
5 changed files with 80 additions and 32 deletions

View File

@@ -17,6 +17,7 @@ import {
isFormConnected,
sanitizeHtml,
validateResponseModeConfiguration,
prepareFormFields,
} from '../utils';
describe('FormTrigger, parseFormDescription', () => {
@@ -994,4 +995,40 @@ describe('validateResponseModeConfiguration', () => {
expect(() => validateResponseModeConfiguration(webhookFunctions)).not.toThrow();
});
describe('prepareFormFields', () => {
it('should resolve expressions in html fields', async () => {
webhookFunctions.evaluateExpression.mockImplementation((expression) => {
if (expression === '{{ $json.formMode }}') {
return 'Title';
}
});
const result = prepareFormFields(webhookFunctions, [
{
fieldLabel: 'Custom HTML',
fieldType: 'html',
elementName: 'test',
html: '<h1>{{ $json.formMode }}</h1>',
},
]);
expect(result[0].html).toBe('<h1>Title</h1>');
});
it('should prepare hiddenField', async () => {
const result = prepareFormFields(webhookFunctions, [
{
fieldLabel: '',
fieldName: 'test',
fieldType: 'hiddenField',
},
]);
expect(result[0]).toEqual({
fieldLabel: 'test',
fieldName: 'test',
fieldType: 'hiddenField',
});
});
});
});