# Change Element another view

**URL:** <https://forum.inductiveautomation.com/t/change-element-another-view/91601>\
**Category:** Ignition\
**Tags:** python, ignition80, scripting, ignition81, perspective\
**Created:** [June 10, 2024, 6:36am UTC](https://forum.inductiveautomation.com/t/change-element-another-view/91601 "2024-06-10T06:36:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emanuel\_Danielczyk](https://avatars.discourse-cdn.com/v4/letter/e/4da419/32.png) [@Emanuel\_Danielczyk](https://forum.inductiveautomation.com/u/Emanuel_Danielczyk)\
**Post date:** [June 10, 2024, 6:36am UTC](https://forum.inductiveautomation.com/t/change-element-another-view/91601/1 "2024-06-10T06:36:30Z")

</div>

Hello, I want to change the props of a text field in another view by clicking on a button. I have created an onClick event with the command `self.getParent().getSibling("Nachfrage ob reset").getChild("TextField").Props.text = "Hello"` , but I am getting the following error message.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/4/54598df10a62362d166291ac4777666112874759.png)

My structure looks like this. My Button is in the container that is highlighted in blue  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/2/9216c67860eef0a381528f27b588041bc1da211f.png)

---

<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:** [June 10, 2024, 6:49am UTC](https://forum.inductiveautomation.com/t/change-element-another-view/91601/2 "2024-06-10T06:49:44Z")

</div>

You can't. And it doesn't make much sense anyway: at runtime, the other view "doesn't exist", so why would you want to change its properties ?

If one is nested in the other, then you can access the instance of the inner one from the outer one.  
If they're supposed to both run in different pages, you could use messages.  
If the properties are supposed to be persistent, then the view doesn't matter.

What exactly are you trying to do ?  
And I suggest you read this before answering: [https://xyproblem.info/](https://xyproblem.info/)

---

<div class="post-metadata">

**Author:** ![Emanuel\_Danielczyk](https://avatars.discourse-cdn.com/v4/letter/e/4da419/32.png) [@Emanuel\_Danielczyk](https://forum.inductiveautomation.com/u/Emanuel_Danielczyk)\
**Post date:** [June 10, 2024, 7:40am UTC](https://forum.inductiveautomation.com/t/change-element-another-view/91601/3 "2024-06-10T07:40:59Z")

</div>

I have the following dashboard to filter information. With the 'Eingaben zurücksetzen' button, I want to reset all inputs, and I have done that with the following script:

> **dashboard**
>
> ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/b/abcfa89ac22d7e2eb6766c9d71cad97ca4b08e84.png)

> **Code to reset**
>
> ```python
> #Funktion, um alle Angaben zu löschen
> self.getSibling("InputQualitaetszentrum").props.value = None #Angaben zu Qualitaetszentrum löschen 
> self.getSibling("InputClients").props.value = None #Angaben zu Clients löschen
> self.getSibling("InputModell").props.value = None #Angaben zu Modell löschen
> self.getSibling("InputErgebnis").props.value = None #Angaben zu Ergebnis löschen
> self.getSibling("InputEinzelergebnis").props.value = None #Angaben zu Einzelergebnis löschen
> self.getSibling("Input_DTC_Device").props.value = None #Angaben zu DTC_Device löschen
> self.getSibling("Input_DTC_SPN").props.value = None #Angaben zu DTC_SPN löschen
> self.getSibling("Input_DTC_FMI").props.value = None #Angaben zu DTC_FMI löschen
> self.getSibling("InputStartDatum").props.value = None #Angaben zu StartDatum löschen
> self.getSibling("InputEndeDatum").props.value = None #Angaben zu EndeDatum löschen
> self.getSibling("InputVIN").props.text = "" #Angaben zu VIN löschen
> self.getSibling("InputProduktionsnummer").props.text = "" #Angaben zu Produktionsnummer löschen
> 	
> 
> ```

Now, I also want a pop-up window to open first and ask me if I really want to reset everything. I wanted to configure an onclick event for the 'Ja' button to reset the inputs and wanted to use the same code as before, navigating from one view to another by using `getParent`, `getSibling`, and `getChild` to navigate through the views and components.

> **Pop-up**
>
> ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/8/6801fe4283fd4885e4ceb01d9c757bdef032f1be.png)

My idea was to navigate to the level of the components of the other view with the 'Ja' button with following Code:

> **Code idea**
>
> ```
> `self.getParent().getSibling("Start Dashboard").getChild("XXX").props.value = None`
> 
> ```

---

<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:** [June 10, 2024, 8:00am UTC](https://forum.inductiveautomation.com/t/change-element-another-view/91601/4 "2024-06-10T08:00:38Z")

</div>

The standard way of doing this is through messages.  
You'd have the popup button on click event send a message, and a message handler on the view that contains the form would catch that.

Turns out confirmation is something that's generic enough to be templatized. Here's what I suggest:

Create a view for the popup. Have it take (at least) those parameters:

- popup id : You'll use this to make sure you close the right popup when clicking buttons
- message type : That's the name of the message handler you'll have on the form. You'll use this as a parameter when calling `system.perspective.sendMessage`
- display message : That's a message to display in the popup. This will probably be something like "Are you sure you want to do x ?"

This popup will contain a label or some other component used to display text. Bind it to the display message parameter.  
It will also have 2 buttons, one to confirm and one to cancel.  
Both buttons will call `system.perspective.sendMessage` then `system.perspective.closePopup`.  
The difference lies in the payload passed to `sendMessage`.  
The confirm button will pass something like

```python
{'confirmed': True}

```

and the cancel one will pass

```python
{'confirmed': False}

```

Now, on the view that contains the form, right click the component that seems appropriate and add a script. I suggest doing this on the smallest container that contains all the input fields.  
Add a message handler, give it a recognizable name (maybe "reset\_form", something like this). This name is what you'll pass to the popup for the `message_type` parameter.  
This script for this handler will check the received payload if `confirmed` is `True`, and if that's the case run whatever script you want. In your case, reset the form's fields.

Notes:

- I suggest putting the reset code in a component method, and calling it from the message handler (so you can also call it from a "reset button", or other events if needed). It's always better to separate things anyway.
- The "confirmed: False" is not necessary in this case, so you can just close the popup when clicking the "cancel" button. BUT, in some cases it's useful to know that the confirmation was denied, so if you want to be able to reuse that popup I suggest you leave that in. You just won't use the cancel payload in your specific case.
- You can add parameters and items in the payload if needed. I know I often also include a "source identifier", that's used to differentiate between several components that are on the same view and that use the same message handler.
