# Set Text Focus On Perspective module

**URL:** <https://forum.inductiveautomation.com/t/set-text-focus-on-perspective-module/58789>\
**Category:** Ignition\
**Tags:** ignition81, scripting, perspective\
**Created:** [April 25, 2022, 3:37am UTC](https://forum.inductiveautomation.com/t/set-text-focus-on-perspective-module/58789 "2022-04-25T03:37:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![yifeiliu08](https://avatars.discourse-cdn.com/v4/letter/y/bbe5ce/32.png) [@yifeiliu08](https://forum.inductiveautomation.com/u/yifeiliu08)\
**Post date:** [April 25, 2022, 3:37am UTC](https://forum.inductiveautomation.com/t/set-text-focus-on-perspective-module/58789/1 "2022-04-25T03:37:49Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/7/17c07291149bb3d55b16fdeb991ad2724363253f.png)

```auto
self.getSibling("ScanWO").focus()

```

I have try to use the focus scripting in the perspective.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/6/363dc908e2b9f19a3a066811a525d9b74d9968d8.png)  
current situation is when I clike the button , it will add the data after the previous data  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/0/e07fc388a49ea66941ed894f59257ba2903248ab.png)

What I want is if I click the button , the previous text will become blue  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/b/bbf98bdef6810de57a5f4dc410bfc56cedab6d6e.png)  
then the new data can replace the old data( I use Scanner as input)

this is very easy in vision , but I don’t know how to make it works in perspective.  
Thanks a lot

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [April 25, 2022, 6:04am UTC](https://forum.inductiveautomation.com/t/set-text-focus-on-perspective-module/58789/2 "2022-04-25T06:04:30Z")

</div>

It doesn’t seem to be programmable at the moment. See [Perspective TextField SelectAll OnFocus](https://forum.inductiveautomation.com/t/perspective-textfield-selectall-onfocus/45826). You could use the button script to set the text to “”.

---

<div class="post-metadata">

**Author:** ![yifeiliu08](https://avatars.discourse-cdn.com/v4/letter/y/bbe5ce/32.png) [@yifeiliu08](https://forum.inductiveautomation.com/u/yifeiliu08)\
**Post date:** [April 25, 2022, 6:36am UTC](https://forum.inductiveautomation.com/t/set-text-focus-on-perspective-module/58789/3 "2022-04-25T06:36:42Z")

</div>

noted and thanks

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [April 25, 2022, 1:08pm UTC](https://forum.inductiveautomation.com/t/set-text-focus-on-perspective-module/58789/4 "2022-04-25T13:08:28Z")

</div>

You could ‘css hack’ it:  
Create a new style, call it `highlight-text`, then in one its field (for example the background image), paste this: `}.psc-highlight-text::first-line { background-color: blue;}{` (replace blue by whatever color you need/want)  
Now, add the `highlight-text` class to your input field on your button’s `actionPerformed` event script to enable the effect, and remove it + delete the text when you get your new data.

edit:  
You can also put that css bit, without the first and last brackets, in a custom theme file. You’ll still need to create the style class. Make sure the names match, with the `psc-` prefix in your css selector.

---

<div class="post-metadata">

**Author:** ![yifeiliu08](https://avatars.discourse-cdn.com/v4/letter/y/bbe5ce/32.png) [@yifeiliu08](https://forum.inductiveautomation.com/u/yifeiliu08)\
**Post date:** [April 25, 2022, 2:46pm UTC](https://forum.inductiveautomation.com/t/set-text-focus-on-perspective-module/58789/5 "2022-04-25T14:46:04Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/7/07e3698f7d1aab32949e5f66613025f6d7166fc8.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/3/d3a213b2af55418f273226513460c595191b8b39.png)

upside is my understanding of your part explain I first adjust the component ScanWO, but I don’t know the following word how to handle

Now, add the `highlight-text` class to your input field on your button’s `actionPerformed` event script to enable the effect, and remove it + delete the text when you get your new data.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/d/1d05ac7ce96316ec1d312729cb92319f28eb3466.png)  
can you show me some picture , thanks a lot

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [April 25, 2022, 3:23pm UTC](https://forum.inductiveautomation.com/t/set-text-focus-on-perspective-module/58789/6 "2022-04-25T15:23:32Z")

</div>

You forgot the `}{` in your css: `}.psc-highlight-text::first-line { background-color: blue;}{`

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/d/cd49c91598e169002c5945980fe2bb2783199bcb.png)  
You need to start with a closing bracket and end with an opening bracket, to inject css. Yes, it’s not pretty.  
OR  
You use `.psc-highlight-text::first-line { background-color: blue;}` without the brackets, in the theme css file (something like `/usr/local/bin/ignition/data/modules/perspective/themes/your_theme.css`)

Then, in your button’s `onActionPerformed` event, add something like this:

```python
classes = self.getSibling("TextField").props.style.classes.split(' ')
classes = set(classes) | set(["highlight-text"])
self.getSibling("TextField").props.style.classes = ' '.join(classes)

```

Then, when you need to replace the data in the text field,  
do the opposite:

```python
classes = self.getSibling("TextField").props.style.classes.split(' ')
classes = set(classes) - set(["highlight-text"])
self.getSibling("TextField").props.style.classes = ' '.join(classes)

```

---

<div class="post-metadata">

**Author:** ![yifeiliu08](https://avatars.discourse-cdn.com/v4/letter/y/bbe5ce/32.png) [@yifeiliu08](https://forum.inductiveautomation.com/u/yifeiliu08)\
**Post date:** [April 26, 2022, 12:54am UTC](https://forum.inductiveautomation.com/t/set-text-focus-on-perspective-module/58789/7 "2022-04-26T00:54:08Z")

</div>

> [@pascal.fragnoud](#):
>
> ```auto
> classes = self.getSibling("TextField").props.style.classes.split(' ')
> classes = set(classes) | set(["highlight-text"])
> self.getSibling("TextField").props.style.classes = ' '.join(classes)
> 
> ```

it works for the color change, thanks a lot
