> For the complete documentation index, see [llms.txt](https://synoint.gitbook.io/survey-library/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://synoint.gitbook.io/survey-library/source-code-api/suffixes-and-prefixes.md).

# Suffixes and prefixes

{% hint style="info" %}
If you already use [Numeric validation](/survey-library/source-code-api/numeric-validation.md) in the open text, you must add this code first. Otherwise, it won't work.

This code has been tested to be fully compatible with it.
{% endhint %}

Create your open text question and set a custom label.

<figure><img src="/files/TxPclQDuS3upGmTfDrpX" alt=""><figcaption><p>Fig 1. Adding an open text and settip up the label</p></figcaption></figure>

Copy and paste the following code into the Javascript editor within the page.

<figure><img src="/files/otqmW7SPqgZkzoiODrT4" alt=""><figcaption><p>Fig 2. Copying and paste the code below this image into the Javascript editor.</p></figcaption></figure>

{% code lineNumbers="true" %}

```javascript
function add_label({question_code, type = "suffix"} = {}) {
	label = document.querySelector("#q_" + question_code + "_card > label");
	label_text = label.innerText;
	label.remove();

	input = document.querySelector("#p_" + question_code + "_1");
	container = document.querySelector("#q_" + question_code + "_card");

	if (type == "suffix") {
		wrapper = `
			<div class="input-group">
				` + input.outerHTML + `
				<div class="input-group-append">
					<span class="input-group-text" style="margin-top: 15px">` + label_text + `</span>
				</div>
			</div>
		`
	} else if (type == "prefix") {
		wrapper = `
		<div class="input-group">
			<div class="input-group-prepend">
				<span class="input-group-text" style="margin-top: 15px">` + label_text + `</span>
			</div>
			` + input.outerHTML + `
		</div>
		`
	}

	input.remove();
	container.innerHTML += wrapper;
}

/* Change this part of the code with your parameters */
add_label({
	question_code : "Q1", 
	type : "prefix"
});
```

{% endcode %}

### How to use it...

Then, you will need to change this part of the code with your actual parameters.

`question code` is the code of your open text.

`type` is the modifier that allows you to specify whether the label should be converted to prefix or suffix.&#x20;

<pre class="language-javascript"><code class="lang-javascript">add_label({
<strong>	question_code : "Q1", 
</strong><strong>	type : "prefix"
</strong>});
</code></pre>

Once done, you should save changes by clicking the <mark style="color:blue;">**save**</mark> button in the Javascript editor.

### Variables

<table><thead><tr><th width="187.33333333333331">Variable name</th><th width="230">Description</th><th>Example</th></tr></thead><tbody><tr><td><code>question_code</code></td><td>The name of the open text where you want to convert it's label as prefix or suffix.</td><td><pre class="language-javascript"><code class="lang-javascript">add_label({
<strong>	question_code : "Q1", 
</strong>	type : "prefix"
});
</code></pre></td></tr><tr><td><code>type</code></td><td><p>The type of label you want. It can be <code>prefix</code> or <code>suffix</code>. </p><p></p><p>if <code>type</code> is not defined, the default value will be <code>suffix</code>.</p></td><td><pre class="language-javascript"><code class="lang-javascript">add_label({
	question_code : "Q1", 
<strong>	type : "prefix"
</strong>});

/\* OR \*/

add\_label({
question\_code : "Q1", <strong>	type : "suffix" </strong>}); </code></pre></td></tr></tbody></table>

### Examples

The label you have just modified will go from looking like this:

<figure><img src="/files/OOczdr8J2jqoPSXrEfTM" alt=""><figcaption><p>Fig 3. Default layout of labels in open text questions</p></figcaption></figure>

To look like this when the label is converted to a <mark style="color:red;">**prefix**</mark>

<pre class="language-javascript"><code class="lang-javascript">add_label({
	question_code : "Q1", 
<strong>	type : "prefix"
</strong>});
</code></pre>

<figure><img src="/files/XtKIdHqCG1aZH9cP1Qnb" alt=""><figcaption><p>Fig 4. Converting a label to prefix</p></figcaption></figure>

or to this other design, in case it has been converted to a <mark style="color:red;">**suffix**</mark>.

<pre class="language-javascript"><code class="lang-javascript">add_label({
	question_code : "Q1", 
<strong>	type : "suffix"
</strong>});
</code></pre>

<figure><img src="/files/zRMC0d2W4tifeZD7pxaZ" alt=""><figcaption><p>Fig 5. Converting a label to suffix</p></figcaption></figure>
