How can I pass default value to textarea of n8n form?

I use Telegram node to send a message and wait for response. The user should receive my json and edit it. Since default form doesn’t have initial value field, I am trying to use a custom form defined as JSON:
[
{
“fieldType”: “html”,
“elementName”: “content”,
“html”: “<textarea>{{ $json }}</textarea>”
}
]

So, I should have a JSON inside of JSON. I tried different options to escape the $json, like: jsonStringify, `JSON.stringify(), `| escape`, `replace()` to replace “ with ‘ or to replace`” with \”, but none of them worked for me.

What is the right way to do what I need? Ideally the textarea should contain the value as is (i.e. double quotes instead of single).

Thanks. I’ve corrected my code in the initial question to better reflect what I am doing.

I have to use html fieldType instead of textarea, since I want to define the initial value and not the placeholder.

Yea , but custom HTML content is read-only, these fields aren’t included in the form output data by default.

The HTML field doesn’t support <script>, <style>, or <input> elements as docs statements…

My brain hurts right now lol… first I need a coffee…

1 Like

Hmm, what is the purpose of elementName field then?

By default, Custom HTML fields are not includeed in the form output because they re display-only. If yu set an ‘elementName”, n8n will include the raw HTML under that name in the output itemn…

Its pourpose is to decide whether (and under what key)) the HTML content should appear in the node’s output data.

Thanks. It means it will work for me.

I managed to get it working with the following replacements:
(omg, I can not insert the code properly; the forum engine replaces my double quotes and double slashes with something else, even if it part of the code)

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.