# Trigger a button Click with text entry

**URL:** <https://forum.inductiveautomation.com/t/trigger-a-button-click-with-text-entry/37507>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [August 7, 2020, 3:31pm UTC](https://forum.inductiveautomation.com/t/trigger-a-button-click-with-text-entry/37507 "2020-08-07T15:31:57Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![trevormorrissound](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/trevormorrissound/32/17225_2.png) [@trevormorrissound](https://forum.inductiveautomation.com/u/trevormorrissound)\
**Post date:** [August 7, 2020, 3:31pm UTC](https://forum.inductiveautomation.com/t/trigger-a-button-click-with-text-entry/37507/1 "2020-08-07T15:31:57Z")

</div>

Got thrown on an ignition project that has mostly been built and I do the PLC stuff and its been fine. I figured out most of the scripting stuff I’ve needed to in order to interact properly with the HMI however last minute they want me to have a “validate” button be triggered after a text box is filled. I’m new to ignition and really am not sure how to accomplish this. I’m using a barcode scanner that is acting as a USB keyboard so I was thinking of ‘property change’ or ‘key released’ as my script trigger and then use component.onClick() function call. Not sure if I’m goin in the right direction. The scanner blasts values into the text box and I would like it to trigger an adjacent button when it is done ‘typing’. This button also has scripting that was provided by another integrator. Some pointing in the correct direction would be appreciated.

---

<div class="post-metadata">

**Author:** ![wking](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/wking/32/21823_2.png) [@wking](https://forum.inductiveautomation.com/u/wking)\
**Post date:** [August 7, 2020, 3:39pm UTC](https://forum.inductiveautomation.com/t/trigger-a-button-click-with-text-entry/37507/2 "2020-08-07T15:39:20Z")

</div>

What do your scanned strings look like?

There is a scanner input component you can use. That looks for certain patterns.

Otherwise. The direction you are going is not wrong. I tend to do that kind of stuff with events that call component methods.

If the bar code scanner can tab out of the text field. After a scan. You might consider using the lost focus event. Instead.

I usually make sure the string is matches some kind of format. First.

Post more info and we will help you.

---

<div class="post-metadata">

**Author:** ![trevormorrissound](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/trevormorrissound/32/17225_2.png) [@trevormorrissound](https://forum.inductiveautomation.com/u/trevormorrissound)\
**Post date:** [August 7, 2020, 3:45pm UTC](https://forum.inductiveautomation.com/t/trigger-a-button-click-with-text-entry/37507/3 "2020-08-07T15:45:50Z")

</div>

They are just Char, Int, Int, Int, Int. This was a last minute thing they threw at me So they look like G2342 and normally user would hit the ‘validate button’ but now that I added a scanner they want the validate button to trigger on its own. I already have it checking format on the PLC side and throwing pop ups but not sure how to trigger an event in another object based off of key presses stopping or that field having a value present. I know some traditional programming but this is my first ignition project. Python is similar to java sort of and I know some java, I was thinking I need to assign the button component to a variable and then trigger its click fucntion but not sure what event from the text field would be a valid ‘green light’ to do that. I tried some stuff yesterday and was crashing it.

---

<div class="post-metadata">

**Author:** ![wking](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/wking/32/21823_2.png) [@wking](https://forum.inductiveautomation.com/u/wking)\
**Post date:** [August 7, 2020, 4:30pm UTC](https://forum.inductiveautomation.com/t/trigger-a-button-click-with-text-entry/37507/4 "2020-08-07T16:30:34Z")

</div>

So i would set the scanner up to tab out of field after a read. Then I would use a onCompositionEnd event to call your code.

---

<div class="post-metadata">

**Author:** ![trevormorrissound](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/trevormorrissound/32/17225_2.png) [@trevormorrissound](https://forum.inductiveautomation.com/u/trevormorrissound)\
**Post date:** [August 7, 2020, 6:48pm UTC](https://forum.inductiveautomation.com/t/trigger-a-button-click-with-text-entry/37507/5 "2020-08-07T18:48:16Z")

</div>

Ok, reading…

I had on my text box under “property change”  
button = event.source.parent.getComponent(“button 2”)  
button.doClick()

It sort of almost works it keeps calling the button click. Looking up your suggestion

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 7, 2020, 6:51pm UTC](https://forum.inductiveautomation.com/t/trigger-a-button-click-with-text-entry/37507/6 "2020-08-07T18:51:55Z")

</div>

> [@trevormorrissound](#):
>
> it keeps calling the button click

That sounds like your propertyChange script isn't checking which property changed. You _ **must** _ have an `if` statement in propertyChange events that checks event.propertyName....

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [August 7, 2020, 6:53pm UTC](https://forum.inductiveautomation.com/t/trigger-a-button-click-with-text-entry/37507/7 "2020-08-07T18:53:12Z")

</div>

@pturmel beat me to it, but you need to narrow down the property change event you want to catch, IE

```auto
if event.propertyName == 'text':
  execute your script

```

---

<div class="post-metadata">

**Author:** ![trevormorrissound](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/trevormorrissound/32/17225_2.png) [@trevormorrissound](https://forum.inductiveautomation.com/u/trevormorrissound)\
**Post date:** [August 7, 2020, 7:10pm UTC](https://forum.inductiveautomation.com/t/trigger-a-button-click-with-text-entry/37507/8 "2020-08-07T19:10:41Z")

</div>

Is there something I should know about binding components to variables, forgive my noobness. It was calling the click before I put the if statement but now getting errors. My code:

button = event.source.parent.getComponent(“button 2”)  
if event.propertyName == ‘text’:  
button.onClick()

---

<div class="post-metadata">

**Author:** ![trevormorrissound](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/trevormorrissound/32/17225_2.png) [@trevormorrissound](https://forum.inductiveautomation.com/u/trevormorrissound)\
**Post date:** [August 7, 2020, 7:12pm UTC](https://forum.inductiveautomation.com/t/trigger-a-button-click-with-text-entry/37507/9 "2020-08-07T19:12:38Z")

</div>

er doClick

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [August 7, 2020, 7:14pm UTC](https://forum.inductiveautomation.com/t/trigger-a-button-click-with-text-entry/37507/10 "2020-08-07T19:14:16Z")

</div>

Try this, Jython is a structured language so white space matters. Where many languages have brackets to determine scope, Python/Jython uses white space for this. Use two spaces for indention or a tab

```auto
if event.propertyName == 'text':
  button = event.source.parent.getComponent('button 2')
  button.doClick()

```

---

<div class="post-metadata">

**Author:** ![trevormorrissound](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/trevormorrissound/32/17225_2.png) [@trevormorrissound](https://forum.inductiveautomation.com/u/trevormorrissound)\
**Post date:** [August 7, 2020, 7:21pm UTC](https://forum.inductiveautomation.com/t/trigger-a-button-click-with-text-entry/37507/11 "2020-08-07T19:21:35Z")

</div>

Attribute error: ‘NoneType’ object has no attribute ‘doClick’ leads me to believe I’m not binding the component to the variable correctly

---

<div class="post-metadata">

**Author:** ![trevormorrissound](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/trevormorrissound/32/17225_2.png) [@trevormorrissound](https://forum.inductiveautomation.com/u/trevormorrissound)\
**Post date:** [August 7, 2020, 7:22pm UTC](https://forum.inductiveautomation.com/t/trigger-a-button-click-with-text-entry/37507/12 "2020-08-07T19:22:38Z")

</div>

Or calling an existing function on it, although other examples that does seem like a possible way to do it, usually can do function calls on variables in other languages confused

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [August 7, 2020, 7:27pm UTC](https://forum.inductiveautomation.com/t/trigger-a-button-click-with-text-entry/37507/13 "2020-08-07T19:27:55Z")

</div>

> [@trevormorrissound](#):
>
> Attribute error: ‘NoneType’ object has no attribute ‘doClick’ leads me to believe I’m not binding the component to the variable correctly

Yes, `getComponent` is returning `None`--no component. Did you replace the curly quotes in the forum post (`“button 2”`) with straight quotes (`"button 2"`)? Otherwise, component name or path to it are wrong.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [August 7, 2020, 7:29pm UTC](https://forum.inductiveautomation.com/t/trigger-a-button-click-with-text-entry/37507/14 "2020-08-07T19:29:59Z")

</div>

Good catch @witman. I altered my previous post to use the correct straight quotes.

---

<div class="post-metadata">

**Author:** ![trevormorrissound](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/trevormorrissound/32/17225_2.png) [@trevormorrissound](https://forum.inductiveautomation.com/u/trevormorrissound)\
**Post date:** [August 7, 2020, 7:35pm UTC](https://forum.inductiveautomation.com/t/trigger-a-button-click-with-text-entry/37507/15 "2020-08-07T19:35:05Z")

</div>

Facepalm, that worked. Havn’t had to do syntax heavy stuff like this for a few years. Also the white space I learned on java where I could indent or not. Thanks witman and hayes!

---

<div class="post-metadata">

**Author:** ![trevormorrissound](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/trevormorrissound/32/17225_2.png) [@trevormorrissound](https://forum.inductiveautomation.com/u/trevormorrissound)\
**Post date:** [August 7, 2020, 7:41pm UTC](https://forum.inductiveautomation.com/t/trigger-a-button-click-with-text-entry/37507/16 "2020-08-07T19:41:14Z")

</div>

For the record it actually took it with single quotes.  
if event.propertyName == ‘text’:  
button = event.source.parent.getComponent(‘Button 2’)  
button.doClick()

I also saw on another post I could have done this

event.source.parent.getComponent(‘Button 2’).doClick()

Without doing a var assign, did not try it though.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [August 7, 2020, 8:21pm UTC](https://forum.inductiveautomation.com/t/trigger-a-button-click-with-text-entry/37507/17 "2020-08-07T20:21:27Z")

</div>

You really need to surround your code on this forum within three ` characters, or use the preformatted function. Python, as people have mentioned, is a space-driven language. Without the preserved space formatting, it’s impossible to read

---

<div class="post-metadata">

**Author:** ![trevormorrissound](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/trevormorrissound/32/17225_2.png) [@trevormorrissound](https://forum.inductiveautomation.com/u/trevormorrissound)\
**Post date:** [August 7, 2020, 8:48pm UTC](https://forum.inductiveautomation.com/t/trigger-a-button-click-with-text-entry/37507/18 "2020-08-07T20:48:12Z")

</div>

My bad I’m new to this forum and python, thanks for the tip.

---

<div class="post-metadata">

**Author:** ![brad.barbin](https://avatars.discourse-cdn.com/v4/letter/b/e19b73/32.png) [@brad.barbin](https://forum.inductiveautomation.com/u/brad.barbin)\
**Post date:** [August 18, 2020, 3:35pm UTC](https://forum.inductiveautomation.com/t/trigger-a-button-click-with-text-entry/37507/19 "2020-08-18T15:35:17Z")

</div>

Is there an equivalent to doClick() in perspective? This code won’t compile:

```auto
if event.key == "Enter":
		button = self.getSibling('LoadLotsButton')
		button.doClick()

```

Here is the error I’m seeing:

```auto
Error running action 'dom.onKeyPress' on Home@D/root/InputMaterialID: 
Traceback (most recent call last): 
File " ", line 6, in runAction 
AttributeError: 'com.inductiveautomation.perspective.gateway.script' object has no attribute 'doClick'

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 18, 2020, 4:32pm UTC](https://forum.inductiveautomation.com/t/trigger-a-button-click-with-text-entry/37507/20 "2020-08-18T16:32:59Z")

</div>

No. `doClick` in Vision is solving the problem in the wrong way in the first place. Put any significant business logic into a project script, and call it with whatever arguments are necessary, from whatever call sites.  
If you _don’t_ want to do a project script, then at least put it into a custom method on the component. Then the button’s `actionPerformed` can call its custom method, and wherever else you need to call the code can as well - just send a message, and have a message handler on the button that also calls the custom method.

[Next page](https://forum.inductiveautomation.com/t/trigger-a-button-click-with-text-entry/37507.md?page=2)
