# Error emptying formatted text field

**URL:** <https://forum.inductiveautomation.com/t/error-emptying-formatted-text-field/88327>\
**Category:** Ignition\
**Tags:** ignition81, scripting, vision\
**Created:** [April 4, 2024, 7:38am UTC](https://forum.inductiveautomation.com/t/error-emptying-formatted-text-field/88327 "2024-04-04T07:38:51Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Om33](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@Om33](https://forum.inductiveautomation.com/u/Om33)\
**Post date:** [April 4, 2024, 7:38am UTC](https://forum.inductiveautomation.com/t/error-emptying-formatted-text-field/88327/1 "2024-04-04T07:38:51Z")

</div>

Hello,

I have a script in vision to set the text of a formatted text field component to empty and when the field is empty then some code lines should be executed.

Thats how I set the text of the formatted text field component to empty:

```auto
event.source.parent.getComponent('Id_Field').text=""

```

And this is how I check if the field is empty:

```auto
id_to_filter=event.source.parent.getComponent('Id_Field').text
if id_to_filter=="":

```

My problem is that, this evaluation is always false because the text field is not empty but shows this instead:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/1/d172d7c582e5508c3b88662a4daad289a65f4097.png)

How can I remove or avoid that space? I don't know where the space comes from. My code is really that simple.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [April 4, 2024, 8:31am UTC](https://forum.inductiveautomation.com/t/error-emptying-formatted-text-field/88327/2 "2024-04-04T08:31:35Z")

</div>

How do you set your formatting? regex or formatted mask? I imagine those parameters will hold the answer to your question.

---

<div class="post-metadata">

**Author:** ![Om33](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@Om33](https://forum.inductiveautomation.com/u/Om33)\
**Post date:** [April 4, 2024, 8:36am UTC](https://forum.inductiveautomation.com/t/error-emptying-formatted-text-field/88327/3 "2024-04-04T08:36:37Z")

</div>

Validation mode is formatted mask:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/1/f1c4eb78a7dd968dd709128fed77f2c71262f27b.png)

I don't understand how this could be related to the problem.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [April 4, 2024, 8:39am UTC](https://forum.inductiveautomation.com/t/error-emptying-formatted-text-field/88327/4 "2024-04-04T08:39:14Z")

</div>

The text will be the length of your formatted mask.

---

<div class="post-metadata">

**Author:** ![Om33](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@Om33](https://forum.inductiveautomation.com/u/Om33)\
**Post date:** [April 4, 2024, 8:42am UTC](https://forum.inductiveautomation.com/t/error-emptying-formatted-text-field/88327/5 "2024-04-04T08:42:53Z")

</div>

Ahn, I see. How can I avoid this then?

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [April 4, 2024, 8:48am UTC](https://forum.inductiveautomation.com/t/error-emptying-formatted-text-field/88327/6 "2024-04-04T08:48:17Z")

</div>

Add `.strip()` to the end of your scripted `text` property, so the whitespace is removed, and your code will work as intended:

```auto
if id_to_filter.strip()=="":

```

---

<div class="post-metadata">

**Author:** ![Om33](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@Om33](https://forum.inductiveautomation.com/u/Om33)\
**Post date:** [April 4, 2024, 8:59am UTC](https://forum.inductiveautomation.com/t/error-emptying-formatted-text-field/88327/7 "2024-04-04T08:59:02Z")

</div>

Thank you! Is there no possibility to also remove that whitespace from the field so that the cursor is set to the beginning of the field?

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [April 4, 2024, 9:02am UTC](https://forum.inductiveautomation.com/t/error-emptying-formatted-text-field/88327/8 "2024-04-04T09:02:25Z")

</div>

> [@Om33](#):
>
> so that the cursor is set to the beginning of the field?

Adding this to your formatted text field's `focusGained` event handler would do that for you:

```auto
event.source.setCaretPosition(0)

```

It won't remove the white space, but it will position your cursor where you want it.

---

<div class="post-metadata">

**Author:** ![Om33](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@Om33](https://forum.inductiveautomation.com/u/Om33)\
**Post date:** [April 4, 2024, 9:09am UTC](https://forum.inductiveautomation.com/t/error-emptying-formatted-text-field/88327/9 "2024-04-04T09:09:55Z")

</div>

Just tried it. Okay in that case it is better to let the cursor at the end

---

<div class="post-metadata">

**Author:** ![Om33](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@Om33](https://forum.inductiveautomation.com/u/Om33)\
**Post date:** [April 4, 2024, 10:32am UTC](https://forum.inductiveautomation.com/t/error-emptying-formatted-text-field/88327/10 "2024-04-04T10:32:58Z")

</div>

This doesn't work 😩

---

<div class="post-metadata">

**Author:** ![Om33](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@Om33](https://forum.inductiveautomation.com/u/Om33)\
**Post date:** [April 5, 2024, 6:50am UTC](https://forum.inductiveautomation.com/t/error-emptying-formatted-text-field/88327/11 "2024-04-05T06:50:00Z")

</div>

Maybe someone from inductive automation could help?

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [April 5, 2024, 7:38am UTC](https://forum.inductiveautomation.com/t/error-emptying-formatted-text-field/88327/12 "2024-04-05T07:38:36Z")

</div>

> [@Om33](#):
>
> This doesn't work

Be more specific. Is the problem still cursor placement?

---

<div class="post-metadata">

**Author:** ![Om33](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@Om33](https://forum.inductiveautomation.com/u/Om33)\
**Post date:** [April 5, 2024, 7:38am UTC](https://forum.inductiveautomation.com/t/error-emptying-formatted-text-field/88327/13 "2024-04-05T07:38:59Z")

</div>

Sorry it is working:)  
I had an error somewhere else
