Om33
April 4, 2024, 7:38am
1
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:
event.source.parent.getComponent('Id_Field').text=""
And this is how I check if the field is empty:
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:
How can I remove or avoid that space? I don't know where the space comes from. My code is really that simple.
How do you set your formatting? regex or formatted mask? I imagine those parameters will hold the answer to your question.
Om33
April 4, 2024, 8:36am
3
Validation mode is formatted mask:
I don't understand how this could be related to the problem.
The text will be the length of your formatted mask.
Om33
April 4, 2024, 8:42am
5
Ahn, I see. How can I avoid this then?
Add .strip()
to the end of your scripted text
property, so the whitespace is removed, and your code will work as intended:
if id_to_filter.strip()=="":
Om33
April 4, 2024, 8:59am
7
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?
Adding this to your formatted text field's focusGained
event handler would do that for you:
event.source.setCaretPosition(0)
It won't remove the white space, but it will position your cursor where you want it.
Om33
April 4, 2024, 9:09am
9
Just tried it. Okay in that case it is better to let the cursor at the end
Om33
April 5, 2024, 6:50am
11
Maybe someone from inductive automation could help?
Om33:
This doesn't work
Be more specific. Is the problem still cursor placement?
Om33
April 5, 2024, 7:38am
13
Sorry it is working:)
I had an error somewhere else
1 Like