# onClick event options binding?

**URL:** <https://forum.inductiveautomation.com/t/onclick-event-options-binding/98675>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [November 15, 2024, 4:57pm UTC](https://forum.inductiveautomation.com/t/onclick-event-options-binding/98675 "2024-11-15T16:57:18Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![JeremyMills](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jeremymills/32/70121_2.png) [@JeremyMills](https://forum.inductiveautomation.com/u/JeremyMills)\
**Post date:** [November 15, 2024, 4:57pm UTC](https://forum.inductiveautomation.com/t/onclick-event-options-binding/98675/1 "2024-11-15T16:57:18Z")

</div>

I have a view I'm embedding in a few different places in a project. In a site overview page, it can be clicked to open a popup with available controls. In a system overview page, I want to use the same embedded view, but disable to onClick event. is there a way to bind the enable option? or is there another way to accomplish this so I don't have to make a second copy of this view without the onClick event?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/5/25a97afa46882c16a64e401ffa5f74152c810254.png)

---

<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:** [November 15, 2024, 6:02pm UTC](https://forum.inductiveautomation.com/t/onclick-event-options-binding/98675/2 "2024-11-15T18:02:56Z")

</div>

The only way forward is to use a script action to open the popup; the script can have whatever arbitrary logic you want as a predicate.

---

<div class="post-metadata">

**Author:** ![JeremyMills](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jeremymills/32/70121_2.png) [@JeremyMills](https://forum.inductiveautomation.com/u/JeremyMills)\
**Post date:** [November 15, 2024, 6:08pm UTC](https://forum.inductiveautomation.com/t/onclick-event-options-binding/98675/3 "2024-11-15T18:08:43Z")

</div>

I haven't used a script action before. Are you suggesting that I fire a script when the onClick event happens? I then check if the view is being accessed from the site overview page or the other location before actually launching the popup using the script?

---

<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:** [November 15, 2024, 6:15pm UTC](https://forum.inductiveautomation.com/t/onclick-event-options-binding/98675/4 "2024-11-15T18:15:27Z")

</div>

Instead of a 'Popup' action, add a 'Script' action.

Your condition/predicate for whether to actually do anything is "am I on the overview page or not", so your script will be something like:

```python
if self.view.id.partition("@")[0] != "Path/To/SystemOverview":
	system.perspective.openPopup(...)

```

You'll have to translate the popup action settings you have defined to [`system.perspective.openPopup`](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-perspective/system-perspective-openPopup).

---

<div class="post-metadata">

**Author:** ![JeremyMills](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jeremymills/32/70121_2.png) [@JeremyMills](https://forum.inductiveautomation.com/u/JeremyMills)\
**Post date:** [November 15, 2024, 6:16pm UTC](https://forum.inductiveautomation.com/t/onclick-event-options-binding/98675/5 "2024-11-15T18:16:59Z")

</div>

Ok great. That's not too hard to implement. Thank you for your help, Paul.

---

<div class="post-metadata">

**Author:** ![JeremyMills](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jeremymills/32/70121_2.png) [@JeremyMills](https://forum.inductiveautomation.com/u/JeremyMills)\
**Post date:** [November 15, 2024, 6:43pm UTC](https://forum.inductiveautomation.com/t/onclick-event-options-binding/98675/6 "2024-11-15T18:43:27Z")

</div>

I'm not seeing documentation about the partition part of that code snipet you sent. Can you explain what the self.view.id.partition("@")[0] does?

---

<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:** [November 15, 2024, 6:50pm UTC](https://forum.inductiveautomation.com/t/onclick-event-options-binding/98675/7 "2024-11-15T18:50:44Z")

</div>

So, given:

1. `self`
2. `view`
3. `id`
4. `partition`
5. `[0]`

* * *

1. In an action script on something in Perspective, `self` identifies the component or whatever other thing is firing the script.
2. All Perspective components have built-in helper functions, `getView()`, `getSession()`, etc. Jython lets you call those getter methods automatically as property references; so `.view` is the same as `getView()` but less characters.
3. View objects in particular have a `getId()`/`id` property: [Perspective Component Methods | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/scripting-in-perspective/perspective-component-methods#view-objects) that returns a string like `path/to/view@mountPath`.
4. You only care about the path to the view, not the 'mount path', so you can use Python's built in [`partition` instance method](https://docs.python.org/2.7/library/stdtypes.html#str.partition) on the string to split it into three parts: the part before the split, the split itself, and the part after.
5. But we only care about the part before the split, so we use index access `[0]` to retrieve that 0th element of the list.

---

<div class="post-metadata">

**Author:** ![JeremyMills](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jeremymills/32/70121_2.png) [@JeremyMills](https://forum.inductiveautomation.com/u/JeremyMills)\
**Post date:** [November 15, 2024, 7:40pm UTC](https://forum.inductiveautomation.com/t/onclick-event-options-binding/98675/8 "2024-11-15T19:40:02Z")

</div>

This is super helpful and I'm learning a lot. However, it's not quite giving me what I need. To check out what i'm getting back, I set up a string tag and filled it with the results of the `self.view.id.partition("@")[0]` function. It's returning the path to the embedded view, not the view that's displayed on the page. How do I get the view that's displayed on the page?

---

<div class="post-metadata">

**Author:** ![JeremyMills](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jeremymills/32/70121_2.png) [@JeremyMills](https://forum.inductiveautomation.com/u/JeremyMills)\
**Post date:** [November 15, 2024, 9:38pm UTC](https://forum.inductiveautomation.com/t/onclick-event-options-binding/98675/9 "2024-11-15T21:38:30Z")

</div>

I was able to solve the problem with

```python
if self.page.props.path != "/": #checks if current page is system home URL. Returns true when NOT system home URL.
	system.perspective.openPopup(...) #opens controls popup

```

I can add additional exclusions with or statements if I need to use this embedded view in other locations.

---

<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:** [November 15, 2024, 10:57pm UTC](https://forum.inductiveautomation.com/t/onclick-event-options-binding/98675/10 "2024-11-15T22:57:44Z")

</div>

> [@JeremyMills](#):
>
> How do I get the view that's displayed on the page?

It's complicated for embedded views, because they live much more in isolation (on the backend, where your scripts are actually being run) than they do on the frontend where they're nested inside each other.
